N
Nick
In the code below, class Z inherits from T<1> and T<2>. Both parents have
pure virtual members of the same name V(), which are overloaded in Z.
How do I define those overloaded members outside of Z? Currently, they are
defined inside the class declaration and this works fine. The problem is
that I cannot define them outside of Z as
void Z::T<1>::V()
{ cout<< "Z(1)" << endl; }
There must be some special syntax for this.
Thanks.
---------------------------------
#include <iostream>
using namespace std;
template< int N >
struct T {
T() { m_N = N; cout<< "T(" << m_N << ")" << endl;}
~T() { cout<< "~T(" << m_N << ")" << endl;}
void S() { V(); }
virtual void V() = 0;
int m_N;
};
struct Z: private T<1> , private T<2> {
Z() { }
void Do()
{
T<1>::S();
T<2>::S();
}
void T<1>::V() { cout<< "Z(1)" << endl; }
void T<2>::V() { cout<< "Z(2)" << endl; }
};
void main( int argc, char* argv[])
{
Z z;
z.Do();
}
pure virtual members of the same name V(), which are overloaded in Z.
How do I define those overloaded members outside of Z? Currently, they are
defined inside the class declaration and this works fine. The problem is
that I cannot define them outside of Z as
void Z::T<1>::V()
{ cout<< "Z(1)" << endl; }
There must be some special syntax for this.
Thanks.
---------------------------------
#include <iostream>
using namespace std;
template< int N >
struct T {
T() { m_N = N; cout<< "T(" << m_N << ")" << endl;}
~T() { cout<< "~T(" << m_N << ")" << endl;}
void S() { V(); }
virtual void V() = 0;
int m_N;
};
struct Z: private T<1> , private T<2> {
Z() { }
void Do()
{
T<1>::S();
T<2>::S();
}
void T<1>::V() { cout<< "Z(1)" << endl; }
void T<2>::V() { cout<< "Z(2)" << endl; }
};
void main( int argc, char* argv[])
{
Z z;
z.Do();
}