By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Prevent hiding -- add an overload instead.

P: n/a

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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.