小编Jer*_*rry的帖子

在Visual Studio 2008中使用指向模板函数的指针编译错误

我正在尝试创建一个模板类,它存储一个模板函数的函数指针,但在Visual Studio 2008中遇到了编译错误.我为它创建了一个简化的测试用例(见下文),它仍然无法在VS2008中编译,但似乎在我尝试的在线Comeau和在线GCC编译器上成功编译.

我看到的错误是:

error C2436: 'func' : member function or nested class in constructor initializer list
temp.cpp(21) : while compiling class template member function 'test_class<T>::test_class(T (__cdecl &))'
1>        with
1>        [
1>            T=int (const int &)
1>        ]
Run Code Online (Sandbox Code Playgroud)

使用非模板功能的相同测试有效.除此之外,是否有人知道该问题的解决方法,或者VS2008是否期望某种不同的语法?

谢谢,

杰瑞

template<class T>
T template_function(const T& arg)
{
    return arg;
}

int non_template_function(const int& arg)
{
    return arg;
}

template<class T>
class test_class
{
public:
    test_class(const T& arg) : func(arg) {}
private:
    T func;
};

template<class T>
void create_class(const …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2008

11
推荐指数
1
解决办法
609
查看次数

标签 统计

c++ ×1

visual-studio-2008 ×1