H
Howard
Hi,
I have a function in three unrelated but similar classes. The code in the
member functions is identical for all three classes. What I want is to make
a template which defines the function, implemented as a non-static member of
each class. Aside from this function, there is no reason the three classes
should inherit from a common base class, which is why I thought a template
would be good. But I can't figure out the syntax for a template which
specifies itself as a member function of the specified class. Also, how
would each class declare the member function?
I tried variations of this, but no luck:
template <class T>
void <T>::foo() // syntax errors here
{
// ...do stuff here...
}
class A
{
void foo<A>();
};
class B
{
void foo<B>();
};
class C
{
void foo<C>();
};
Thanks,
-H
I have a function in three unrelated but similar classes. The code in the
member functions is identical for all three classes. What I want is to make
a template which defines the function, implemented as a non-static member of
each class. Aside from this function, there is no reason the three classes
should inherit from a common base class, which is why I thought a template
would be good. But I can't figure out the syntax for a template which
specifies itself as a member function of the specified class. Also, how
would each class declare the member function?
I tried variations of this, but no luck:
template <class T>
void <T>::foo() // syntax errors here
{
// ...do stuff here...
}
class A
{
void foo<A>();
};
class B
{
void foo<B>();
};
class C
{
void foo<C>();
};
Thanks,
-H