Hello Experts!
I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that I don't understand
completely.
Im I right if I say the following.
In this case is the derived class a class template and the base class a
class template.
Both the base class and the derived class will be instansiated with some
specific type T
template <typename T>
class MyStack : public Stack<T> {. . .}
You cannot derive a concreate class from a class template as in
class IntStack : public Stack<T,100> {. . .} why.
Is it because the base class will not be instantiated with a type.
I mean if the base class could be instansiated with a type then this kind of
inheritance should be valid.
What does this text try to say..
"Instantiat ions of template are unrelated, even if classes for these
instantiations
are in a inheritance relation(that is, one is derived from the other). For
example,
given a general BankAccount class that has a derived class CheckingAccount ,
there is no inheritance relation between Stack<BankAccou nt> and
Stack<CheckingA ccount>".
Many thanks
//Tony 1 1562
I think what the text is trying to say is that you cannot derive IntStack
from Stack without instantiating Stack template with a specific type.
Put it this way:
a class template is NOT a type;
an instantiation of a class template, however, is a type (e.g.
Stack<int, 100>);
you can only inherit from a type.
So if T is not a type declared/defined previously, then Stack<T> is not a
type, you can't derive from it.
For example:
class PatientRecord{} ;
template <typename T>
class Stack{};
template <typename T>
class SafeStack: public Stack<T> // OK
{
// Ok, Stack<T> is a type where
// T is a template parameter type.
};
class PatientRecordSt ack: public Stack<PatientRe cord>
{
// Ok, Stack<PatientRe cord> is a type
};
class SomeStack: public Stack<T>
{
// Error, Stack<T> is not a type,
// because T is not defined.
}; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas Matthews |
last post by:
Hi,
I would like to apply inheritance to a template parameter, but my design
fails to compile: cannot initialize one template class with child
child parameterized class. I'll explain...
Given:
#include <string>
// Parent class
|
by: Jeff Greenberg |
last post by:
Not an experienced c++ programmer here and I've gotten myself a bit
stuck. I'm trying to implement a class lib and I've run into a sticky
problem that I can't solve. I'd appreciate any help that I can get!
Consider 3 classes in the following heirarchy:
base
/ \
deriv1 deriv2
\
|
by: darkstorm |
last post by:
I have a doubt regarding inheritance involving templates
Consider this:
/////////////////////////////////////
template<typename T>
class A
{
private:
T m_a;
|
by: Tony Johansson |
last post by:
Hello experts!
I have two class template below with names Array and CheckedArray.
The class template CheckedArray is derived from the class template Array
which is the base class
This program works fine but there in one thing that I'm unsure about
and that is the inheritance statement.
What difference is it if I have this construction
class CheckedArray : public Array<T>
|
by: Steve Jorgensen |
last post by:
A while back, I started boning up on Software Engineering best practices and
learning about Agile programming. In the process, I've become much more
committed to removing duplication in code at a much finer level. As such,
it's very frustrating to be working in VBA which lacks inheritance, one of the
more powerful tools for eliminating duplication at the level I'm talking
about.
I've recently come up with a technique to emulate one...
| |
by: Digital Puer |
last post by:
I'm not the world's greatest C++ programmer, so I had a hard
time with these. Some help would be appreciated.
1. Comment on the declaration of function Bar() below:
class Foo
{
static int Bar(int i) const;
}
(I said that since Bar is a static method, it can only access
|
by: Massimo |
last post by:
Hi to all, I'm facing a problem in a particularly complex inheritance
hierarchy, and I'd like to know what the standard says about it and if my
compiler is correct in what it does.
I have two consecutive layers of diamond-shaped inheritance; the first layer
is declared as using virtual inheritance, while the second one is declared
as *not* using it.
This is what I'd like to have:
|
by: Jess |
last post by:
Hello,
It seems both static_cast and dynamic_cast can cast a base class
pointer/reference to a derived class pointer/reference. If so, is
there any difference between them?
In addition, if I have a derived class object and then upcast it to
its base class, which cast operator should I use? Is it static_cast,
or, can I simply cast it implicitly without any operator? Does this
upcasting remove the derived class portion of the object?...
|
by: puzzlecracker |
last post by:
The statement is taken from FAQ . What about non-virtual
functions? Can they be overriden? I still don't see a good
justification to prefer private inheritance over composition. In
fact, I have never seen it in a commercial code. If someone did,
please share the use-case and decisions behind it.
Thanks
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |