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

Prevent hiding -- add an overload instead.


Is there any way to prevent hiding of a base class function? I want the
derived class to add an overload of the function, rather than hide the
base class one. The following snippet demonstrates what I'm after:

class Type1 {};
class Type2 {};

class Base {
public:

void Func( Type1 )
{
;
}

};
class Derived : public Base {
public:

void Func( Type2 )
{
;
}

};

int main()
{
Derived derived_obj;

Type1 type1_obj;

derived_obj.Func(type1_obj); /* Any way to make this work? */
/* Instead of having to do: */
static_cast<Base&>(derived_obj).Func( type1_obj );
}

--

Frederick Gotham
Jul 2 '06 #1
2 1534
Frederick Gotham posted:

Is there any way to prevent hiding of a base class function? I want the
derived class to add an overload of the function, rather than hide the
base class one.

It's OK, I figured it out.
class Type1 {};
class Type2 {};

class Base {
public:

void Func( Type1 )
{
;
}

};
class Derived : public Base {
public:

using Base::Func;

void Func( Type2 )
{
;
}

};

int main()
{
Derived derived_obj;

Type1 type1_obj;

Type2 type2_obj;

derived_obj.Func(type1_obj);

derived_obj.Func(type2_obj);
}

--

Frederick Gotham
Jul 2 '06 #2

"Frederick Gotham" <fg*******@SPAM.comskrev i meddelandet
news:sY*******************@news.indigo.ie...
>
Is there any way to prevent hiding of a base class function? I want
the
derived class to add an overload of the function, rather than hide
the
base class one. The following snippet demonstrates what I'm after:

class Type1 {};
class Type2 {};

class Base {
public:

void Func( Type1 )
{
;
}

};
class Derived : public Base {
public:
using Base::Func; // Now it is visible here!
void Func( Type2 ) // and an overload added
{
;
}

};

Bo Persson
Jul 2 '06 #3

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

Similar topics

7
by: Piotre Ugrumov | last post by:
I have tried to implement the overload of these 2 operators. ostream & operator<<(ostream &out, Person &p){ out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl; return out; }...
5
by: Amir S. | last post by:
Hi, I'm a newbie to C++ (2 weeks into the course). We were given this assignment to write some code that reads a set of integers (grades) from a file (filename passed by console), outputs them...
7
by: Philippe Guglielmetti | last post by:
I spent hours chasing a stupid bug of this kind: std::string bad='x'+"yz"; // results in anything except "xyz" ("yz" was in fact returned by some class::operator char*() conversion...) Any...
7
by: Tron Thomas | last post by:
Under the right compiler the following code: class Base { public: virtual void Method(int){} }; class Derived: public Base {
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
1
by: Eric Cadwell | last post by:
I'm inheriting from From, but my Show method requires a parameter, so I define an overloaded Show method: public void Show(Form Owner) Now I get intellisence for two methods: Control.Show()...
17
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: ...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
9
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function...
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
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...
0
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...

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.