templates and initialization problems

Started by
5 comments, last by pcxmac 20 years, 8 months ago
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);
sig
Advertisement
With templates you also need to define the members in the header along with declaring them.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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.
sig
Typos. You are using "()" instead of "<>".
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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?

};"
sig
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]
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement