8
这是我的代码: 虚拟继承在vs2013
#include <vector>
struct A
{
typedef std::vector<int> vec; //(1) template type
virtual A& test(vec) = 0;
};
struct B : public virtual A //(2) virtual inheritance
{
virtual B& test(vec) override //(3) covariant return type
{
return *this;
}
};
//std::vector<int> vv, cc(vv); //(4) explicit instantiate copy-ctor
int main()
{
B b;
b.test({});
}
的Visual C++ 2013给了我一个链接错误。
error LNK2001: unresolved external symbol "public: __thiscall
std::vector<int,class std::allocator<int> >::vector<int,class
std::allocator<int> >(class std::vector<int,class
std::allocator<int> > const &)"
([email protected][email protected]@[email protected]@@[email protected]@[email protected]@@Z)
我试过gcc,它编译。
如果我做下列事情任一项,VC将编译:
- 更改的行(1)到非模板类型
- 删除“虚拟”的线(2)
- 改变在该行返回类型甲&(3)
- 取消对线(4)
为什么呢?
现场测试链接:http://rextester.com/XZA77022 – ecatmur 2014-09-25 15:27:47
看起来像一个VC bug。 – 2014-09-25 15:40:09
当您怀疑有错误时,您应该提供确切的编译器版本。 VC++ 2013不是一个确切的版本,有4个更新(如服务包)以及特定的错误修复。您应该打开Visual Studio工具命令提示符并输入'cl'来获得完整版本 – 2014-11-20 22:40:06