Обновление ниже .
Ниже приведен весь код, который есть в моем файле main.cpp:
template<class T>
struct other_traits;
template<class T>
struct some_traits{
typedef decltype(&T::operator()) Fty;
typedef typename other_traits<Fty>::type type;
};
int main(){
}
Но я получаю следующие ошибки в Visual Studio 2010, пока g ++ прекрасно компилируется :
src \ main.cpp (9): ошибка C2146: синтаксическая ошибка: отсутствует ';'перед идентификатором 'type'
--src \ main.cpp (10): см. ссылку на экземпляр шаблона класса 'some_traits<T>
', который компилируется
src \ main.cpp (9): ошибка C2868: 'some_traits<T>::type
': недопустимый синтаксис для объявления об использовании;ожидаемое квалифицированное имя
(мне нравится это последнее, общее вес.)
Могу ли я считать это ошибкой в VC10 или есть какая-то веская причина для раннего создания экземпляра?Или это ошибка с decltype
, из-за которой компилятор считает, что Fty
не является зависимым именем?
Обновление : я пытался обмануть компилятор, думая, чтоFty
является зависимым именем, использующим базовый класс для наследования:
template<class T>
struct other_traits;
template<class R, class C>
struct other_traits<R (C::*)()>{
typedef R type;
};
template<class Fty>
struct base_traits{
typedef typename other_traits<Fty>::type type;
};
template<class T>
struct some_traits
: public base_traits<decltype(&T::operator())>
{};
Но компилятор все еще пытается создать экземпляр / скомпилировать все на месте, выпуская эти ошибки:
src\main.cpp(13): error C2039: 'type' : is not a member of 'other_traits<T>'
with
[
T=
]
src\main.cpp(19) : see reference to class template instantiation 'base_traits<Fty>' being compiled
with
[
Fty=
]
src\main.cpp(19) : see reference to class template instantiation 'some_traits<T>' being compiled
src\main.cpp(13): error C2146: syntax error : missing ';' before identifier 'type'
src\main.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
src\main.cpp(13): error C2602: 'base_traits<Fty>::type' is not a member of a base class of 'base_traits<Fty>'
with
[
Fty=
]
src\main.cpp(13) : see declaration of 'base_traits<Fty>::type'
with
[
Fty=
]
src\main.cpp(13): error C2868: 'base_traits<Fty>::type' : illegal syntax for using-declaration; expected qualified-name
with
[
Fty=
]
Обратите внимание, что параметры шаблона пусто .Есть идеи?