Need help - Advanced architecture

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::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.
 
V

Victor Bazarov

David2511 said:
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() {};
^^
Extraneous semicolon. Remove it.
virtual T& MethodOne() = 0;
static A<T>* CreateA(bool p_bParam = false);
};

//-------------------------------------------------------

template <class T> class B
: public template <class T> class A

template said:
{
public:
B();
virtual ~B() {};
virtual T& MethodOne() {return m_oAttribut;};

Remove the extraneous semicolons.
protected:
T m_oAttribut;
};

//-------------------------------------------------------

template <class T> class C
: public template <class T> class A

template said:
{
public:
C();
virtual ~C() {};
virtual T& MethodOne() {return m_oAttribut;};

Drop the extraneous semicolons here too.
protected:
T m_oAttribut;
};

//-------------------------------------------------------

template<class T>
void A<T>::CreateA(bool p_bParam /*= false*/)

template<class T>
A said:
{
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;
}
;
^^^
Here you lost a semicolon.
D::D()
{
toto = A<long>::CreateA(true);
}

It is better to initialise than to assign. Rewrite as

D::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 ?

See above.
Is it possible to implement this architecture with standard C++ ?

As soon as you have defined all the necessary functions, it should be OK.

V
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top