Problem with inner classes of the same name in Visual C++
- by starblue
I have a problem with Visual C++, where apparently inner classes with the same name but in different outer classes are confused.
The problem occurs for two layers, where each layer has a listener interface as an inner class. B is a listener of A, and has its own listener in a third layer above it (not shown).
The structure of the code looks like this:
A.h
class A
{
class Listener
{
Listener();
virtual ~Listener() = 0;
}
[...]
}
B.h
class B : public A::Listener
{
class Listener
{
Listener();
virtual ~Listener() = 0;
}
[...]
}
B.cpp
B::Listener::Listener() {}
B::Listener::~Listener() {}
I get the error
B.cpp(49) : error C2509: '{ctor}' : member function not declared in 'B'
The C++ compiler for Renesas sh2a has no problem with this, but then it is more liberal than Visual C++ in some other respects, too.
If I rename the listener interfaces to have different names the problem goes away, but I'd like to avoid that (the real class names instead of A or B are rather long).
Is what I'm doing correct C++, or is the complaint by Visual C++ justified?
Is there a way to work around this problem without renaming the listener interfaces?