I was shocked today by the fact that this code snippet has an ambiguous name reference:
class A
{
private:
typedef int Type;
};
class B
{
public:
typedef int Type;
};
class D : A, B
{
Type value;//error: reference to 'Type' is ambiguous
};
Hmm! Imagine you are the author of class A
and your class has already been used everywhere by different people and different projects. One day you decide to rewrite your A
class. Doesn't this mean that you cannot use any new (even private) name in your new class without breaking others' code?
What is the convention here?
Yes you are right. Using the current format/logic/coding style might break others' code if you decide to make changes later. Try to use PIMPL or fully qualify symbols. You're example is a good one of why it's not a good idea to not use fully qualify symbols. It's the same issue with code like:
using namespace std;
The line of code above could break a lot of stuff.
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