I have the following C++ code:
class ident {};
class Base {
public:
int ident;
};
class Derived : public Base {
::ident var; // refers to the global identifier
ident var; // syntax error, refers to the base member
};
Is it possible to make it so ident refers to the global variable in Derived::method()? Eventually completely hiding Base::ident? I cannot change Base, but I can make an intermediate class. I can add lines everywhere but the generation of the member variables will always refer to ident as ident.
It is a very unusual request, because it is for a templated code generator (SWIG).
>Solution :
If you make the base depend on a template parameter:
template <typename T>
class DerivedLow : public T
{
void method()
{
ident = 0; // Refers to the global entity.
}
};
using Derived = DerivedLow<Base>;
Then nothing from the base class will be accessible in the derived class by default. You can still access base members with this-> or Base::, or by importing them with using.