Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Subclassing from parametrized class

Posted on 2004-03-26
5
Medium Priority
?
329 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 500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

604 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