|
-
October 18th, 2003, 01:39 AM
#1
Member
operator<< template error
Hello everybody out there I have a little problem while overloading the <<operator for a class Im doing (named Set) which uses templates. The line that specifically gives me an error is
template <typename Item>
ostream& operator<<(ostream& out, const Set<Item> &S)
the error it gives me is ::
bash-2.05b$ g++ setwithtemplates.cpp
setwithtemplates.cpp:25: warning: friend declaration `std: stream&
operator<<(std: stream&, const set<Item>&)' declares a non-template
function
setwithtemplates.cpp:25: warning: (if this is not what you intended, make sure
the function template has already been declared and add <> after the
function name here) -Wno-non-template-friend disables thi
z€K€ says:
s warning
/tmp/cc7w8oWB.o(.text+0x1d8): In function `main':
: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, set<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)'
collect2: ld returned 1 exit status
THANX
I Speak in frequencies even dogs have trouble hearing
-
October 24th, 2003, 05:25 AM
#2
Junior Member
The code you posted is correct but reading your error shows that the problem does not lie within that line. "warning: friend decleration of operator << declares a non-template function" that gives me the idea that in your class implementation of Set your decleration of the friend function does not match up with its definition. So check out the decleration and if you can't figure it out please post the class definition here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|