473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

template and inheritanc

Hello Experts

To derive a concrete class from a template class in invalid. Why??
So you should not be able have something like this
class Derived : public Base<int, 100>

It's valid to derive a template class from a base class that is also a
template class.
It's valid to derive a template class from a concrete base class.

I do know inheritance but I have never used it together with template
classes.
How should inheritance be understood when we have to do with templated
classes
Can you explain something about that.

Many thanks

//Tony
Aug 16 '05 #1
2 1932
On Mon, 15 Aug 2005 23:55:16 GMT, "Tony Johansson"
<jo*****************@telia.com> wrote:
Hello Experts

To derive a concrete class from a template class in invalid. Why??
So you should not be able have something like this
class Derived : public Base<int, 100>

It's valid to derive a template class from a base class that is also a
template class.
It's valid to derive a template class from a concrete base class.

I do know inheritance but I have never used it together with template
classes.
How should inheritance be understood when we have to do with templated
classes
Can you explain something about that.

Many thanks

//Tony


I strongly recommend that you read the following book:
"C++ Templates -- The Complete Guide"
by David Vandevoorde and Nicolai M. Josuttis
Addison-Wesley (ISBN 0-201-73484-2)

After you've read it, please drop in again.

--
Bob Hairgrove
No**********@Home.com
Aug 16 '05 #2
Tony Johansson wrote:
To derive a concrete class from a template class in invalid.
There is no such thing as a "template class". There is a "class"
and a "class template". I presume you mean the latter.
Why??
Because such are the rules of the language. The base class becomes
a sub-object in th ederived class object. If the base class is
a template, there is no way to create a sub-object, is there? We
can only create objects from a concrete types.
So you should not be able have something like this
class Derived : public Base<int, 100>
Huh???

That's not deriving from a template. That's deriving from a class,
an instantiation of the template. It should work just fine, assuming
that 'Base' is declared, for example, like

template<class T, int a> class Base;
It's valid to derive a template class from a base class that is also a
template class.
(still presuming you mean "class template")... Yes.
It's valid to derive a template class from a concrete base class.
Yes. You can define a class template and give it a base class.
I do know inheritance but I have never used it together with template
classes.
Nothing special. The concepts are orthogonal.
How should inheritance be understood when we have to do with templated
classes
....with class templates... What's different? If you specify some
particular template arguments, the template becomes a concrete type.
Now combine the two concepts.
Can you explain something about that.


What book are you reading that doesn't explain it?

Please do not ask us to write another book for you in a newsgroup
post. Ask specific questions.

V
Aug 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
5
by: Gianni Mariani | last post by:
The spirit of this arguably pointless exercise, is that the numeric_limits<T> class could be replaced with a totally generic template of compile-time, template computed constants. The problem is...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
2
by: Alfonso Morra | last post by:
I have a class declared as ff: class __declspec(dllexport) A { public: A() ; A(const A&) A& operator=(const A&) ; ~A() ; void doThis(void) ;
19
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
9
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.