Archived

This topic is now archived and is closed to further replies.

templates and initialization problems

This topic is 5289 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

ok i have this template class template (class T) class TEMP { TEMP(T* offset, T::*memberFunction); ... }; implimentation : // i like pascal!!! class::class() { TEMP(class)* newTEMP = new TEMP(class) (this,class::function); ... }; // so when i try to compile this crap it says LINK ERROR : undefined sample, and references TEMP::TEMP (class* _var , void (*) (void* _var)); the last argument being the member function pointer. my question is where did i go wrong... and does this sound good for the TEMP constructor? TEMP::TEMP(class* depot, class::*func);

Share on other sites
With templates you also need to define the members in the header along with declaring them.

Share on other sites
im not sure what u mean. could u be more explicit. also there are more members for each class and they are propperly declared. theres no inheritance between the two classes.

Share on other sites
Typos. You are using "()" instead of "<>".

Share on other sites
I think this should be ok (assuming class::function takes no parameters and returns nothing) :

templateclass TEMP { TEMP(T* offset, void (T::*memberFunction)());... };

Share on other sites
"template
class TEMP
{
TEMP(T* objPtr, (void) (T::*memFPtr) (void* _src));
// would this work for the memFPtr if it had arguments?

};"

Share on other sites
quote:

im not sure what u mean. could u be more explicit. also there are more members for each class and they are propperly declared. theres no inheritance between the two classes.

In other words, you would normally declare your class in the header and define each member function (and static member variables) in a .cpp file. You can't do this with templates, both the declarations and definitions need to be in the header. In you're case, you would need to define the TEMP constructor in the header that you declared the class in. So you're header would be something like this...
template<class T>class TEMP{public:    TEMP(T* offset, T::*memberFunction);};template<class T>TEMP<T>::TEMP(T* offset, T::*memberFunction){    // do stuff}

Reading you're post again though, this may not be the problem. If it was I think you'd be getting link errors about multiple definitions rather than stuff being undefined, so please feel free to ignore me

[edited by - joanusdmentia on July 28, 2003 2:32:43 AM]

[edited by - joanusdmentia on July 28, 2003 2:33:56 AM]