문제

Is it possible to do something like this:

class BaseClass
{
public:
    class NestedClass
    {
    };
};

BaseClass foo;
foo.NestedClass bar;

How to get the type from the instance?

도움이 되었습니까?

해결책

What you need to do is the following:

BaseClass::NestedClass bar;

You cannot avoid using the scope resolution operator, but you can make a typedef as a shorthand in the appropriate scope:

typedef BaseCLass::NestedClass NestedClass;

EDIT: Based on the change in question, if you would like the type from an instance, in c++11 you can use decltype:

decltype(foo)::NestedClass;

but this is pointless as decltype would return BaseClass in this instance.

다른 팁

You use the scope resolution operator along with the base class name:

BaseClass::NestedClass bar;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top