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;
} 2 1185
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; }
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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,
|
by: Kai Wu |
last post by:
Hello,
struct S{
friend class B;
private:
int i;
};
class B{
B(){}
|
by: Lionel B |
last post by:
Greetings,
The following code:
<code>
template<typename T>
class A
{
protected:
|
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...
|
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:
| |
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...
|
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?
|
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.
|
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>
|
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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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?
| |
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
| |