Jump to content
  • Advertisement

Archived

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

dabutabey

how can make templates in C++ ??

This topic is 6104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
}

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!