C++ class naming convention for interface classes with a concrete and namespace subclasses
c++, namespaces
Solution
Acknowledging your comment that having all of these same-named types is a bad idea, you can specifically refer to a type in the global namespace by prefixing it with `::`. In this case, that means you can refer to the type `Foo` from the global namespace, while in the context of a naming scope that defines its own `Foo`, by referring to the global one as `::Foo`. So this works:
class IFoo {};
class Foo : public IFoo {};
namespace Bar { class Foo : public ::Foo {}; }
Problem
A convention is the letter "I" proceeding pure virtual interface classes. Often, I find that I also need a partial concrete class with some share functionality for subclasses. So, ``` class IFoo {...} class Foo : public IFoo {...} ``` I run into naming conundrums when I want subclasses derived from Foo differentiated by namespaces. E.g., ``` Bar::Foo Baz::Foo ``` Because when I code ``` namespace Bar { class Foo : public Foo {} } ``` Not surprisingly, VS gives the error "a class cannot be its own base class". (Not an issue when there's no "intermediate class, because the naming is Bar::IFoo, and Baz::IFoo.) I can get around this with ``` class MyFoo : public IFoo namespace Bar { class Foo : public MyFoo {} } ``` or ``` namespace base { class Foo : public IFoo {} } namespace Bar { class Foo : public base::Foo {} } ``` But would prefer not to muddle naming. I get that having classes Foo, Bar::Foo, and Baz::Foo is bad because of the obvious confusion. (E.g., adding "using Bas;" would introduce ambiguity.) Is there a naming convention or syntax that clearly relates what I'm trying to do?