This is my code:
#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 gave me a link error.
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 &)"
(??0?$vector@HV?$allocator@H@std@@@std@@QAE@ABV01@@Z)
I tried gcc, and it compiles.
If I do any one of the following things, VC will compile:
Why?
This is likely a VC bug indeed; Clang and G++ both accept this code. Interestingly enough, changing the code to not use an initializer-list in the call to B.test()
as below also eliminates the error, which leads me to believe that there is a problem with VC++'s initializer list support that is causing this.
#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()
{
A::vec v;
B b;
//b.test({});
b.test(v);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.