473,468 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Create 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(const 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(int) ?

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 1171
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(const 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(int) ?
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****@freemail.hu> wrote in message
news:46**************************@posting.google.c om...
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
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...
2
by: Kai Wu | last post by:
Hello, struct S{ friend class B; private: int i; }; class B{ B(){}
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
1
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...
3
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....
2
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...
12
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...
14
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...
7
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...
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
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...
1
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...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.