Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - template friend member
i'm having trouble figuring out how to use a member function in a header provided like this... template <class T> class foo { public: friend int friendfunc(foo<char> &); // etc... i need to define this function in a separate file, and i'm having a problem with the linker finding this function. anybody know offhand the way to implement and link this? for instance i have: foo.h // header foo.cpp // implementation friend.cpp // friendfunc code main.cpp // the app i've #included the foo.cpp and everything about this template works just fine except this one dang function... everything i do i get Symbol Undefined error from the linker. i hate to give up, any ideas? thanks, bw Oct 22 2002
In foo.cpp, you'll need a reference to the template in order to cause its instantiation. "bw" <bw_member pathlink.com> wrote in message news:ap53g6$eti$1 digitaldaemon.com...i'm having trouble figuring out how to use a member function in a header provided like this... template <class T> class foo { public: friend int friendfunc(foo<char> &); // etc... i need to define this function in a separate file, and i'm having a Oct 23 2002
In article <ap6hf1$2d41$2 digitaldaemon.com>, Walter says...In foo.cpp, you'll need a reference to the template in order to cause its instantiation. Oct 23 2002
Put in foo.cpp the following: foo<char> x; The trick is the compiler, in ff.cpp and main.cpp, does not have the template definition so cannot instantiate the template. In foo.cpp, the compiler doesn't know about the uses of foo in ff.cpp and main.cpp, and in foo.cpp the compiler doesn't know what types to instantiate it with. "bw" <bw_member pathlink.com> wrote in message news:ap6mgp$2its$1 digitaldaemon.com...In article <ap6hf1$2d41$2 digitaldaemon.com>, Walter says...In foo.cpp, you'll need a reference to the template in order to cause its instantiation. Oct 23 2002
In article <ap6q8k$2o0l$1 digitaldaemon.com>, Walter says...Put in foo.cpp the following: foo<char> x; Oct 23 2002
The eponymous term of ultimate respect is "compiler-walter" :) "bw" <bw_member pathlink.com> wrote in message news:ap6qp3$2on8$1 digitaldaemon.com...In article <ap6q8k$2o0l$1 digitaldaemon.com>, Walter says...Put in foo.cpp the following: foo<char> x; Oct 23 2002
Walter is not a person... He is a team... Matthew Wilson wrote:The eponymous term of ultimate respect is "compiler-walter" :) "bw" <bw_member pathlink.com> wrote in message news:ap6qp3$2on8$1 digitaldaemon.com...In article <ap6q8k$2o0l$1 digitaldaemon.com>, Walter says...Put in foo.cpp the following: foo<char> x; Oct 23 2002
|