Reputation: 5728
I inherited some badly named code and got lucky when I received an third party library that made my life even more complicated. This is what I ended up with.
class Something; // third party library
namespace Something {
class Something;
class Templated<class TemplateClass>;
}
Now I need to use the class "Something" from the third party library as the TemplateClass parameter for a new class under namespace Something. I thought this should work
class Something; // third party library
namespace Something {
class Something;
class Templated<class TemplateClass>;
class Impl : public Templated< ::Something > {}
}
But the compiler doesn't like it. The only way I got it to compile was
class Something; // third party library
class Something2 : public Something {} // dirty hack
namespace Something {
class Something;
class Templated<class TemplateClass>;
class Impl : public Templated< Something2 > {}
}
But I don't really like it. There must be a better way to do this.
Upvotes: 1
Views: 811
Reputation: 131907
You could use another namespace:
class Something; // third party library
namespace third_party{
using ::Something;
}
namespace Something {
class Something;
class Templated<class TemplateClass>;
class Impl : public Templated< ::third_party::Something > {}
}
In general, though, I think naming your class and namespace exactly the same is a very bad idea.
Upvotes: 3