Link to home
Start Free TrialLog in
Avatar of NetwrkGuru
NetwrkGuru

asked on

Subclassing from parametrized class

Hi,

Assume, I have a parametrized class:

template <class A>
class CBase
{
public:
CBase() {};
~CBase() {};
}

Can I subclass this file as the follows:

template <class A>
class CBaseSub : public CBase <A>
{
public:
CBaseSub() {};
~CBaseSub() {};
}

Visual C++ 6.0 allows such subclassing but Rational Rose 2001 doesn't allow (it told me 'Cannot subclass from parameterized class').

What is true? Can I subclass from parameterized class?
Avatar of stefan73
stefan73
Flag of Germany image

Hi NetwrkGuru,
> Can I subclass from parameterized class?
Sure, the STL is full of such subclasses.

Cheers,

Stefan
AFAIK this is a valid construct. It seems that Rose has a problem with this. I'm browsing throug "The C++ Programming Language" to find something definitive about this right now.

BTW: The GNU C++ compiler also compiles this withtout warning (even with -Wall)
NetwrkGuru,

See the

  template <typename _Tp, typename _Alloc = allocator<_Tp> >
    class deque : protected _Deque_base<_Tp, _Alloc>

definition, for example.
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Axter
The classes you posted do not end with a semicolon.

Do you have a semicolon on your test code, or is this a typo?