|
-
January 5th, 2006, 11:42 AM
#1
template problem
Hi
Here is my problem:
Code:
class A
{
public:
// Constructor and so on....
template <typename T>
int func(T* const& var);
//....
// in the .cpp:
template <typename T>
int A::func(T* const& var) { var->DoSmth(); return 1; }
I included the header into an other classes cpp like:
Code:
//class B .cpp
void B::somefunc()
{
A a;
CDoSmthClass *ds = new CDoSmthClass();
// now I want to call class A's func
a.func(ds);
// The linker fails at this point saying "... unresolved external... public: int __thiscall A::func.......
When I use the func method eg. in class A's constuctor with the CDoSmthClass it compiles without link error!!???!?
-
January 5th, 2006, 12:18 PM
#2
Re: template problem
include implementation of a::func in header
"Programs must be written for people to read, and only incidentally for machines to execute."
-
January 6th, 2006, 01:25 AM
#3
Re: template problem
There are many, many threads on this issue here .. try searching them here in this forum. You will find what needs to be done. In the meantime look at this FAQ - Why do I get unresolved externals with my template code?. Hope this helps. Regards.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
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
|
Click Here to Expand Forum to Full Width
|