| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Code:
#include <iostream>
using namespace std;
template<class T>
class Stack
{
private:
T* arr;
int size;
public:
friend ostream& operator<<(ostream& os, const Stack& x);
};
template<class T>
ostream& operator<<(ostream& os, const Stack<T>& x)
{
for(int i=0; i < x.size; i++)
os << x.arr[i] << endl;
return os;
}
int main()
{
Stack<int> x;
cout << x << endl;
}
unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Stack<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Stack@H@@@Z) referenced in function _main |
|
#2
|
|||
|
|||
|
Re: template & friend problem
I usually refer to this FAQ whenever I forget the incantation needed to work with template friends:
Why do I get linker errors when I use template friends?
__________________
C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way Kindly rate my posts if you found them useful
|
|
#3
|
|||
|
|||
|
Re: template & friend problem
Thanks!
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|