Solved

Subclassing from parametrized class

Posted on 2004-03-26
5
315 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 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