how can make templates in C++ ??
i am going to get crayz because
i can't make something like this:
i want to make a class like this
class XTY
{
};
simple yeh?
and i want to add a function to this class!
BUUUUT it must be a template function!!
how can i make it?
the function is like this:
template
lump* lump_oku(int lump_no,int Length,int Offset)
{
lump*sss;
//SOME CODE
return &sss
};
How can i add this function to that class???!!!!
PLEASE HELP till I get crayz....
Edited by - dabutabey on November 2, 2001 12:35:23 PM
Make the class a template class:
template <class T>clas XTY{ ret_type func( T &arg_list);}; //template <class T> ret_type XTY::func( T &arg_list){ // function body}
template
class XTY
{
T* lump_oku(int lump_no,int Length,int Offset)
{
T*sss;
//SOME CODE
return &T
};
};
You use T as the data type for the class.
And I declare my class like this
XTY MyTemplateClass;
int* temp;
temp = MyTemplateClass.lump_oku(1,10,0);
class XTY
{
T* lump_oku(int lump_no,int Length,int Offset)
{
T*sss;
//SOME CODE
return &T
};
};
You use T as the data type for the class.
And I declare my class like this
XTY MyTemplateClass;
int* temp;
temp = MyTemplateClass.lump_oku(1,10,0);
Well,
should, I''d have thought, suffice?
All your bases belong to us
class XTY{ template <...> lump* lump_oku(int lump_no,int Length,int Offset);};template <...>lump* lump_oku(int lump_no,int Length,int Offset){lump*sss;//SOME CODEreturn &sss};
should, I''d have thought, suffice?
All your bases belong to us
Thanx Man it worked.
But i think you forgat to put XTY:: infront of the function,or is it neccesery to put?
Anyway it worked!
Thank You very much!!
class XTY
{
template
lump* lump_oku(int lump_no,int Length,int Offset);
};
template
lump* XTY::lump_oku(int lump_no,int Length,int Offset)
{
lump*sss;
//SOME CODE
return &sss
};
But i think you forgat to put XTY:: infront of the function,or is it neccesery to put?
Anyway it worked!
Thank You very much!!
class XTY
{
template
lump* lump_oku(int lump_no,int Length,int Offset);
};
template
lump* XTY::lump_oku(int lump_no,int Length,int Offset)
{
lump*sss;
//SOME CODE
return &sss
};
I think you have to declare template methods inline in MSVC6 otherwise they don''t compile or link correctly (bad mojo otherwise).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement