【发布时间】:2013-09-23 12:00:26
【问题描述】:
代码:
#include <tr1/functional>
class Test
{
public:
Test() { ; }
virtual void foo() = 0;
};
void someFunc(Test& j)
{
j.foo();
}
void func(Test& j)
{
std::tr1::bind(someFunc, std::tr1::ref(j));
}
在Linux上使用g++ 4.8.1,用--std=c++11编译我得到:
In file included from foo.cpp:1:0:
/usr/include/c++/4.8.1/tr1/functional: In instantiation of ‘class std::tr1::reference_wrapper<Test>’:
foo.cpp:17:44: required from here
/usr/include/c++/4.8.1/tr1/functional:495:9: error: cannot allocate an object of abstract type ‘Test’
operator()(_Args&... __args) const
^
foo.cpp:3:7: note: because the following virtual functions are pure within ‘Test’:
class Test
^
foo.cpp:7:18: note: virtual void Test::foo()
virtual void foo() = 0;
^
这似乎没有任何意义。使用相应的 boost 类可以正常工作。有人可以确认这是 G++ 4.8.1 中的 TR1 错误吗?
【问题讨论】:
-
适用于 GCC 4.8 上的非 TR1
std::C++11 等效项。 -
@stefan,
main()不需要编译它,只有当你尝试链接它时。 -
如果您可以访问 GCC4.8(即支持 C++11 的编译器),您为什么要使用技术报告?
-
@stefan,如果你只是添加
main(),运行代码什么都不会告诉你,你仍然不执行func。问题是关于编译错误,而不是运行时行为。