template question

M

makc

This probably sounds dumb but i can't figure it out. I want a class
template that contains a 1000 of funcs that are same for all template
arguments, and 1 func that is different in every case. I tried:

template <class T, int i>
struct TFunc {
int Func (void);
};

int TFunc<char, 5> (void) {
return 0;
};

int main(int argc, char* argv[])
{
TFunc<char, 5> t;


return t.Func();
}

but compiler sends me back to school with this. Please suggest a
workaround?
 
M

makc

This probably sounds dumb but i can't figure it out. I want a class
template that contains a 1000 of funcs that are same for all template
arguments, and 1 func that is different in every case. I tried:

template <class T, int i>
struct TFunc {
int Func (void);

};

int TFunc<char, 5> (void) {
return 0;

};

int main(int argc, char* argv[])
{
TFunc<char, 5> t;

return t.Func();

}

but compiler sends me back to school with this. Please suggest a
workaround?

oh wait, I missed ::Func
 
F

FabioAng

makc said:
This probably sounds dumb but i can't figure it out. I want a class
template that contains a 1000 of funcs that are same for all template
arguments, and 1 func that is different in every case. I tried:

template <class T, int i>
struct TFunc {
int Func (void);
};

int TFunc<char, 5> (void) {
return 0;
};

int main(int argc, char* argv[])
{
TFunc<char, 5> t;


return t.Func();
}

but compiler sends me back to school with this. Please suggest a
workaround?
Do you need something like the following (template full specialization) ?

template <class T, int i>
struct TFunc {
int Func (void);
};

template <>
struct TFunc<char,5> {
int Func (void) {
return 0;
};
};

int main()
{
TFunc<char, 5> t;

return t.Func();
}

Fabio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top