D
David2511
Hello,
I need a little help. I try to write the following architecture :
an abstract template class A
Two classes derived from class A : the classes B and C which are
concrete.
The class A contains a static method called CreateA which allows to
instanciate
one of the two subclasses depending external criterias.
//-------------------------------------------------------
This is implemented by the following code:
template <class T> class A
{
public:
virtual ~A() {};
virtual T& MethodOne() = 0;
static A<T>* CreateA(bool p_bParam = false);
};
//-------------------------------------------------------
template <class T> class B
: public template <class T> class A
{
public:
B();
virtual ~B() {};
virtual T& MethodOne() {return m_oAttribut;};
protected:
T m_oAttribut;
};
//-------------------------------------------------------
template <class T> class C
: public template <class T> class A
{
public:
C();
virtual ~C() {};
virtual T& MethodOne() {return m_oAttribut;};
protected:
T m_oAttribut;
};
//-------------------------------------------------------
template<class T>
void A<T>::CreateA(bool p_bParam /*= false*/)
{
if(p_bParam)
return new B<T>;
else
return new C<T>;
}
//-------------------------------------------------------
I use this code in a class D :
class D
{
D();
~D();
protected:
A<long>* toto;
}
D:()
{
toto = A<long>::CreateA(true);
}
And I have a problem during the link step : Error XXX - Undefined
symbol A<long>::CreateA(bool)
I work with the standard compiler provided par AIX 5.1 (xlC) et the
standard linker (ld).
Can someone help me ?
Is it possible to implement this architecture with standard C++ ?
Thanks for your help.
David2511.
I need a little help. I try to write the following architecture :
an abstract template class A
Two classes derived from class A : the classes B and C which are
concrete.
The class A contains a static method called CreateA which allows to
instanciate
one of the two subclasses depending external criterias.
//-------------------------------------------------------
This is implemented by the following code:
template <class T> class A
{
public:
virtual ~A() {};
virtual T& MethodOne() = 0;
static A<T>* CreateA(bool p_bParam = false);
};
//-------------------------------------------------------
template <class T> class B
: public template <class T> class A
{
public:
B();
virtual ~B() {};
virtual T& MethodOne() {return m_oAttribut;};
protected:
T m_oAttribut;
};
//-------------------------------------------------------
template <class T> class C
: public template <class T> class A
{
public:
C();
virtual ~C() {};
virtual T& MethodOne() {return m_oAttribut;};
protected:
T m_oAttribut;
};
//-------------------------------------------------------
template<class T>
void A<T>::CreateA(bool p_bParam /*= false*/)
{
if(p_bParam)
return new B<T>;
else
return new C<T>;
}
//-------------------------------------------------------
I use this code in a class D :
class D
{
D();
~D();
protected:
A<long>* toto;
}
D:()
{
toto = A<long>::CreateA(true);
}
And I have a problem during the link step : Error XXX - Undefined
symbol A<long>::CreateA(bool)
I work with the standard compiler provided par AIX 5.1 (xlC) et the
standard linker (ld).
Can someone help me ?
Is it possible to implement this architecture with standard C++ ?
Thanks for your help.
David2511.