My question is related to this one: How to publicly inherit from a base class but make some of public methods from the base class private in the derived class?, but my case is a little more complex as I want to change the access for overloaded/template functions:
template<typename T>
class Base
{
public:
void fun(int); //1
void fun(float); //2
void fun(T); //3
template<typename U> //4
void fun(U);
};
template<typename T1, typename T2>
class Derived : private Base<T1>
{
public:
//change access specifier here for:
//1 - make fun(int) available
//2 - fun(float) is really evil and it should not be accessible!
//3 - make fun(T1) == Base::fun(T) available
//4 - make template<typename U> void Base::fun(U) available
};
I've tried the method from previous answer to make some function public, but I get this error:
ISO C++11 does not allow access declarations; use using declarations instead
How can I use using
to make only the selected functions (1, 3 and 4) available for users of Derived
?
Function declarations that differ only by its return type cannot be overloaded with function overloading process. Member function declarations with the same parameters or the same name types cannot be overloaded if any one of them is declared as a static member function.
You can't make the overloaded operator polymorphic itself, but you make the member function it calls virtual , so it acts polymorphic anyway.
Explaination. Overloaded assignment operator does the job similar to copy constructor and is required to be overloaded as member function of the class.
In the case of a friend function, the binary operator should have only two argument and unary should have only one argument. All the class member object should be public if operator overloading is implemented. Operators that cannot be overloaded are . . * :: ?:
As Armen and Jarod pointed out, using
will bring all fun
's in the derived class. Jarod though had a great idea: delete
the evil function! Combining their answers I got this:
template<typename T1, typename T2>
class Derived : private Base<T1>
{
public:
using Base<T1>::fun;
void fun(float) = delete;
};
which does exactly what I wanted originally!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With