2017-05-30 70 views
0

我有这个类的定义(这里简化),它与VS2008编译好。在VS2017,我得到一个语法错误C2059第一角度支架:模板化的类定义不能编译VS2017

template < typename Function, typename Base, typename Specialiser = Base > 
class FunctionTermBase : public Base 
{ 
public: 
    // typedef typename Function::result_type result_type; 
    typedef typename Base term_type; 
    typedef typename Specialiser specialiser; 

protected: 
    FunctionTermBase() { } 

public: 
    template <typename T> 
    struct Specialise { 
     typedef typename specialiser::Specialise<T>::type type; 
    }; 
}; 

我会很感激,如果有人能告诉我什么是错的代码?

+0

***我在第一个角度支架上出现语法错误C2059:***它可能有助于将精确错误消息的文本添加到您的问题。 – drescherjm

回答

3

您必须使用template关键字来指示以下依赖名称也具有模板参数。此外,由于标识符已知为类型(它们是模板参数),因此您的typedef中不需要typename

template < typename Function, typename Base, typename Specialiser = Base > 
class FunctionTermBase : public Base 
{ 
public: 
    // typedef typename Function::result_type result_type; 
    typedef Base term_type; 
    typedef Specialiser specialiser; 

protected: 
    FunctionTermBase() { } 

public: 
    template <typename T> 
    struct Specialise { 
     typedef typename specialiser::template Specialise<T>::type type; 
     //   Add template here ^^^^^^^^ 
    }; 
};