Solved

Subclassing from parametrized class

Posted on 2004-03-26
5
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

729 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