473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inherited member function not seen

Hi
I am a bit confused. I thought always that if a class inherits from
another (public), then all of its base class's public member function
are also visible in this class - even if it declares a function with
the same name, but different parameters.

However, when I try to compile the example below, the compiler claims
that there is no appropriate function:
invalid conversion from 'int' to 'const char *'
initializing argument 1 of 'void B::push_back(co nst char *)'

However, if I don't declare a 'push_back' function inside 'class B',
then everything works fine. Should the compiler in this case not
resolve the
'push_back' function (based on its argument type: int) to
A::push_back(in t) ?

Thank you
DAniel

-----
class A
{ public:
void push_back(int) {}
};

class B : public A
{ public:
void push_back(const char *) {}
};

int main()
{
B b;
b.push_back(1);
return 0;
}
Jul 22 '05 #1
2 1186
Daniel Barna wrote:
Hi
I am a bit confused. I thought always that if a class inherits from
another (public), then all of its base class's public member function
are also visible in this class - even if it declares a function with
the same name, but different parameters.
If you declare a function in a derived class, _all_ functions of its
base classes with the same name are hidden.
However, when I try to compile the example below, the compiler claims
that there is no appropriate function:
invalid conversion from 'int' to 'const char *'
initializing argument 1 of 'void B::push_back(co nst char *)'

However, if I don't declare a 'push_back' function inside 'class B',
then everything works fine. Should the compiler in this case not
resolve the 'push_back' function (based on its argument type: int) to
A::push_back(in t) ?
No. But you can explicitly make it visible in B. See my addition to your
code.
Thank you
DAniel

-----
class A
{ public:
void push_back(int) {}
};

class B : public A
{ public:
void push_back(const char *) {}
using A::push_back;
};

int main()
{
B b;
b.push_back(1);
return 0;
}


Jul 22 '05 #2

"Daniel Barna" <kk****@freemai l.hu> wrote in message
news:46******** *************** ***@posting.goo gle.com...
Hi
I am a bit confused. I thought always that if a class inherits from
another (public), then all of its base class's public member function
are also visible in this class - even if it declares a function with
the same name, but different parameters.

No, you got it wrong. Base class member functions with same name as a
derived class member function are hidden in the derived class.
Should be in the FAQ - http://www.parashift.com/c++-faq-lite
Jul 22 '05 #3

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

Similar topics

8
7691
by: ashok | last post by:
I have a confusion. Do static member functions of base class get inherited to derived class? I searched for this answer but nowhere I get any referencec saying "derived class inherits static functions with other member functions of the base class". regds,
2
1543
by: Kai Wu | last post by:
Hello, struct S{ friend class B; private: int i; }; class B{ B(){}
4
1867
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
1
4343
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an inherited base member's access level in the derived class: its access level in the base class and the type of inheritance (public, protected, or private). After this determination is made, the following possibilities exist for manually changing the...
3
5481
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile. (You must have a <% Register %> so it will see it) You will get TWO warnings per class like:
2
2981
by: lovecreatesbeauty | last post by:
I'm disturbed on this question on a long time. I think if I finally get understand it with your kind help, I will get close to a excellent C++ programmer. And I only can rely on your expertise and help. I've read some books, but no book focuses on this. Don't you think it is a very important thing of C++ programming language? So your knowledge is of great benefit to others, especially me. 1. Which (How many) members will be created...
12
1512
by: Mike - EMAIL IGNORED | last post by:
Within class MyClass, I can think of two ways to tell if MyClass is inherited in a particular use: 1. pass an appropriate bool in the ctor args; 2. use a virtual method that returns, for example, a siring containing the class name. Is there a better way?
14
2640
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming Language, but there isn't a detail and complete description on all the class members, aren't they important to class composing? Could you explain the special class behavior in detail? Thank you very much.
7
1685
by: Daniel Kraft | last post by:
Hi all! I'm getting some for me "unexpected behaviour" from g++ 4.1.2 when compiling this simple test program: #include <cstdlib> #include <cstdio> using namespace std; template<typename t>
0
8989
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, 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...
0
9367
jinu1996
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...
1
9319
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,...
0
9243
tracyyun
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...
0
8241
agi2029
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...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.