Solved

Subclassing from parametrized class

Posted on 2004-03-26
5
313 Views
Last Modified: 2010-04-01
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?
0
Comment
Question by:NetwrkGuru
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

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

Cheers,

Stefan
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10686436
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)
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10686453
NetwrkGuru,

See the

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

definition, for example.
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 125 total points
ID: 10686464
Check chapter 13.6 "Derivation and Templates" in "The C++ Programming Language" for more information.
0
 
LVL 30

Expert Comment

by:Axter
ID: 10697422
The classes you posted do not end with a semicolon.

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now