Archived

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

dabutabey

how can make templates in C++ ??

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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);


Share this post


Link to post
Share on other sites
Well,
  
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 CODE

return &sss;
};

should, I''d have thought, suffice?


All your bases belong to us

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites