Reputation: 10206
I'm breaking up a circular include dependency by forward declaring the class in its respective header, however that puts a small wrinkle in the existing convention of using a type alias inside of a class:
#include <memory>
class C {
public:
using Ptr = std::shared_ptr<C>;
};
Ideally it'd be possible to do something like:
#include <memory>
class C;
using C::Ptr = std::shared_ptr<C>;
But that's not possible because C
isn't a complete type (yet). I realize it's possible to create an alias using CPtr = std::shared_ptr<C>;
, but I was hoping I was missing something obvious using typename
or some other keyword that would establish C
as a complete-enough type for the purpose of creating a nested type alias.
Upvotes: 1
Views: 1005
Reputation: 88155
No, you cannot put something inside of a class except by actually writing it inside the class definition.
It's not an issue of whether C
is a complete type or not. It's simply that C++ does not have any syntax that allows a name to be added to a class scope (or any scope) other than by actually writing it in that scope.
Upvotes: 2