I’ve got a problem with type deduction in Visual Studio 2010. I need to do something like this:
class Outer {
template<typename T> ... SomeTemplateFunction() { ... }
class NestedClass {
std::vector<decltype(SomeTemplateFunction<SomeOtherType>())> stuff;
};
};
However, even after adjusting for the non-staticness of the method
class Outer {
static Outer* null() { return nullptr; }
template<typename T> ... SomeTemplateFunction() { ... }
class NestedClass {
std::vector<decltype(Outer::null()->SomeTemplateFunction<SomeOtherType>())> stuff;
};
};
Visual Studio cries, saying that the outer class is an incomplete type. How can I modify the above snippet to deduce on the return type of the outer class’s template function?
You can define the nested class later
The compiler is right to moan at you. For a class member access (
.and->), unlike for::, the class must be complete. So if it would be a static function, it would be fine, but since it’s a non-static member function, it errors out.An exception to that rule is when the member access happens in a late specified return type of a non-static member function when using
this(generally, in between after the closing)of the parameter list and before the start of the function body, that exception to the rule is allowed. Within a member function body of the inner class, the outer class is regarded complete, so no exception to the rule is needed anymore).