473,385 Members | 1,521 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,385 software developers and data experts.

Class inheritance question

I have 2 classes like this:

class Parent
{
public:
void divide( B* element);
protected:
virtual void divide(A* bd);
}

class Child : public Parent
{
protected:
virtual void divide(A* bd);

}

And I have code which calls this:
Child c;
c.divide(new B());

Why the above code can't compile? Why Child does not inherit 'divide(
B* element);' from Parent?

Thank you.

Jan 28 '06 #1
5 1322
* Al************@gmail.com:
I have 2 classes like this:

class Parent
{
public:
void divide( B* element);
protected:
virtual void divide(A* bd);
}

class Child : public Parent
{
protected:
virtual void divide(A* bd);

}

And I have code which calls this:
Child c;
c.divide(new B());

Why the above code can't compile?
It could, depending on what types B and A are.

However, if B and A are unrelated types it won't compile.

That's because the declaration of divide in Child, _hides_ the inherited
divide(A*), with respect to name lookup.

If that's the problem you're facing, you can add

using Parent::divide;

in class Child.

Why Child does not inherit 'divide( B* element);' from Parent?


It does.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jan 28 '06 #2
Yes. class A and class B are not related.

And why I don't have the same problem in Java?
Thank you.

Jan 28 '06 #3
Hi

Al************@gmail.com wrote:
And why I don't have the same problem in Java?


Just a wild guess... but I think that is because Java is a different
language.

Markus

Jan 29 '06 #4
Al************@gmail.com wrote:
I have 2 classes like this:

class Parent
{
public:
void divide( B* element);
protected:
virtual void divide(A* bd);
}

class Child : public Parent
{
protected:
virtual void divide(A* bd);

}

And I have code which calls this:
Child c;
c.divide(new B());


Congratulations. You have a memory leak (unless Child::divide takes
ownership of the pointer passed to it).
Jan 29 '06 #5
Al************@gmail.com wrote:
I have 2 classes like this:

class Parent
{
public:
void divide( B* element);
protected:
virtual void divide(A* bd);
}
;
class Child : public Parent
{
protected:
virtual void divide(A* bd);

}
;
And I have code which calls this:
int main() {
Child c;
c.divide(new B());
}
Why the above code can't compile? Why Child does not inherit 'divide(
B* element);' from Parent?


Missing semicolons, missing definition of B, missing main etc.

Please post code that compiles, or at least as close as possible.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 30 '06 #6

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

Similar topics

9
by: Tom Evans | last post by:
My basic question: If I have a specific interface which I know is going to be implemented by a number of classes, but there is no implementation commonality between them, what is the preferred...
9
by: mead | last post by:
What kind of classes is qualified as "concrete classes"? When should a member function in a class defined as "pure virtual" and when as "virtual"? Thanks!
8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
1
by: Jodie | last post by:
Hi All, I have a question regarding about inheritance and member of the class. For example I have the class A and class B what is the situation that I need to define class B is base class of class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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?
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...

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.