templates and initialization problems
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);
With templates you also need to define the members in the header along with declaring them.
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.
I think this should be ok (assuming class::function takes no parameters and returns nothing) :
templateclass TEMP { TEMP(T* offset, void (T::*memberFunction)());... };
"template
class TEMP
{
TEMP(T* objPtr, (void) (T::*memFPtr) (void* _src));
// would this work for the memFPtr if it had arguments?
};"
class TEMP
{
TEMP(T* objPtr, (void) (T::*memFPtr) (void* _src));
// would this work for the memFPtr if it had arguments?
};"
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement