内容简介:翻译自:https://stackoverflow.com/questions/26042254/virtual-inheritance-with-covariant-return-type-and-a-template-class-argument-li
这是我的代码:
#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 &)" (??0?$vector@HV?$allocator@H@std@@@std@@QAE@ABV01@@Z)
我试过gcc,然后编译.
如果我执行以下任何一项操作,VC将编译:
>将第(1)行更改为非模板类型
>删除行中的“虚拟”(2)
>将退货类型更改为A&在行(3)
>取消注释线(4)
为什么?
这可能确实是一个VC错误; Clang和G都接受这个代码.有趣的是,在下面的B.test()调用中将代码更改为不使用初始化列表也可以消除错误,这使我相信VC的初始化列表支持存在问题导致此问题.
#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);
}
翻译自:https://stackoverflow.com/questions/26042254/virtual-inheritance-with-covariant-return-type-and-a-template-class-argument-li
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- java中具有继承关系的类及其对象初始化顺序
- 大数据领域开源工具有哪些
- 具有前景的深度学习工具一览
- IT认证具有多大价值?
- IT认证具有多大价值?
- java – 具有搜索实现的CursorTreeAdapter
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
零售的哲学:7-Eleven便利店创始人自述
[日] 铃木敏文 / 顾晓琳 / 江苏文艺出版社 / 2014-12-1 / 36
全球最大的便利店连锁公司创始人——铃木敏文,结合40多年零售经验,为你讲述击中消费心理的零售哲学。铃木敏文的很多创新,现在已经成为商界常识,本书把那些不可思议的零售创新娓娓道来。关于零售的一切:选址、订货、销售、物流、管理……他一次又一次地在一片反对声中创造出零售界的新纪录。 翻开本书,看铃木敏文如何领导7-11冲破层层阻碍,成为世界第一的零售哲学。一起来看看 《零售的哲学:7-Eleven便利店创始人自述》 这本书的介绍吧!
RGB转16进制工具
RGB HEX 互转工具
MD5 加密
MD5 加密工具