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?
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?
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)
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.
See the
template <typename _Tp, typename _Alloc = allocator<_Tp> >
class deque : protected _Deque_base<_Tp, _Alloc>
definition, for example.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The classes you posted do not end with a semicolon.
Do you have a semicolon on your test code, or is this a typo?
Do you have a semicolon on your test code, or is this a typo?
> Can I subclass from parameterized class?
Sure, the STL is full of such subclasses.
Cheers,
Stefan