Archived

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

pcxmac

templates and initialization problems

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 this post


Link to post
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 this post


Link to post
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]

Share this post


Link to post
Share on other sites