By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,367 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,367 IT Pros & Developers. It's quick & easy.

Need help - Advanced architecture

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
David2511 wrote:
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<class T> class B : public A<T>
{
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<class T> class C : public A<T>
{
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<T>* 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;
} ;
^^^
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.