473,386 Members | 1,835 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.

Container Classes

class Base
{
public:
/** class contain1 has only virtual functions. Can they be pure too??
*/
class Contain1
{
virtual void Func1();
virtual void Func2();

}
};

class Derived : Base
{

public:

/** class contain1 v-Functions are overriddable here?? **/

void B1::Contain1().Func1();
void B1::Contain1().Func2();
};
Is this allowed in C++? If not why?

May 13 '06 #1
2 1228
ks*******@gmail.com wrote:
....

Is this allowed in C++? If not why?


No, it is not allowed. You can override methods of the class that is
inherited - i.e. of Base. - Why ? - Because.
May 13 '06 #2
ksngroups wrote:
class Base
{
public:
/** class contain1 has only virtual functions. Can they be pure too??
Any virtual function can be pure.
*/
class Contain1
{
virtual void Func1();
virtual void Func2();

}
};

class Derived : Base
{

public:

/** class contain1 v-Functions are overriddable here?? **/

void B1::Contain1().Func1();
void B1::Contain1().Func2();
};


You probably come from Java-land.

In C++, even though the Base class contains the Contain1 class, a Base
object contains no Contain1 object unless you put it there. Next, each
virtual function anchors to its objects with a secret pointer, or similar
system, inside its object. In your system, only Contain1 contains the secret
pointer to a vtable.

So when you derive, the Derived class objects also get no automatic Contain1
object. So we cannot upgrade C++ to make your curious syntax work, because
Derived has no virtual methods in its vtable, or similar system, to
override.

This would work:

class Derived: public Base::Contain1
{

virtual void Func1();
void Func2();
};

Both override; the "virtual" is optional.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 13 '06 #3

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

Similar topics

5
by: MPowell | last post by:
I'm going through the Koeing book Accelerated C++ in an attempt to understand Container classes. Of course I'm going through a paradigm shift from C to C++. So now I've got struct Header {...
8
by: Markus Dehmann | last post by:
I defined a base class in order to put heterogeneous values into a standard container: All values that I store in the container are derived from my base class. Now when I iterate over the...
6
by: Robert | last post by:
Hello. I have been trying out the Lebans ToolTip Classes at http://www.lebans.com/tooltip.htm, to display "balloon" style help tips in a form. The classes I am using are located at...
4
by: mailcsprasad | last post by:
When to use STL classes and when to use MFC Container classes?
7
by: toton | last post by:
Hi, I want a circular buffer or queue like container (queue with array implementation). Moreover I want random access over the elements. And addition at tail and remove from head need to be low...
1
by: toton | last post by:
Hi, I need to store some suicidal class to a container like deque. ( I am not using boost container library for pointers at this moment, using stl containers). The container stores some session...
1
by: scrier | last post by:
Hi, I wish to have a baseclass A that class B and C inherits from, C is a standard class that has some get and set functions while B is like C only with a container class that can have 1 or...
7
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like...
36
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
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,...

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.