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