how can make templates in C++ ??

Started by
4 comments, last by dabutabey 22 years, 5 months ago
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
Davut Engin
Advertisement
Make the class a template class:
template &ltclass T>clas XTY{   ret_type func( T &arg_list);};  //template &ltclass 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);


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 CODEreturn &sss};  

should, I''d have thought, suffice?


All your bases belong to us
CoV
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
};
Davut Engin
I think you have to declare template methods inline in MSVC6 otherwise they don''t compile or link correctly (bad mojo otherwise).
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement