partial template class

C

Capstar

Hi NG,

Is it possible to make a template class, which has only one method that
makes use of the template type. The rest of the methods will work on the
base class of which the template type should always be derived.
I want the template to have a compile-time check of the type, but I
don't want a "full" template class because all generic methods will be
generated for every type I use this class with, which is a waste of
resources.

Thanks in advance,
Mark
 
J

John Harrison

Capstar said:
Hi NG,

Is it possible to make a template class, which has only one method that
makes use of the template type. The rest of the methods will work on the
base class of which the template type should always be derived.
I want the template to have a compile-time check of the type, but I
don't want a "full" template class because all generic methods will be
generated for every type I use this class with, which is a waste of
resources.

Thanks in advance,
Mark

Its possible to make a template of one method only in an otherwise
non-template class

class X
{
template <class T>
void f(T t);

void g();
void h();
};

Its possible to derive a template class from a non-template base class and
put all the non-templated stuff there.

class XBase
{
void g();
void h();
};

template <class T>
class X : public XBase
{
void f(T t);
};

You're asking for one of those two possibilities I think, I'm not sure which
one so I mentioned both.

john
 
C

Capstar

John said:
Its possible to make a template of one method only in an otherwise
non-template class

class X
{
template <class T>
void f(T t);

void g();
void h();
};

I thought so, but than I can call method f with any kind of type, and as
long as a conversion can be made to the type the rest of the methods
would use, it is OK. So that's not realy what I want since I can't force
a specific type that way.
Its possible to derive a template class from a non-template base class and
put all the non-templated stuff there.

class XBase
{
void g();
void h();
};

template <class T>
class X : public XBase
{
void f(T t);
};


You're asking for one of those two possibilities I think, I'm not sure which
one so I mentioned both.

john

Thanks for your quick reply.
Mark
 

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
474,183
Messages
2,570,966
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top