gpt4 book ai didi

c++ - 错误 C2440 : 'initializing' : cannot convert from 'std::vector<_Ty>' to 'const std::vector<_Ty> &`

转载 作者:太空狗 更新时间:2023-10-29 20:43:30 26 4
gpt4 key购买 nike

<分区>

问题1> 为什么下面的代码不起作用?

问题2>正确的设计方法是什么?

#include <iostream>
#include <vector>
#include "boost/shared_ptr.hpp"

using namespace std;

class BaseClass
{};

class SubClass : public BaseClass
{};

int main()
{
std::vector<boost::shared_ptr<SubClass> > vecSubClassShared;

boost::shared_ptr<SubClass> sub1(new SubClass);

vecSubClassShared.push_back(sub1);

// Error 1 error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'const std::vector<_Ty> &`
const std::vector<boost::shared_ptr<BaseClass> >& vecBaseShared = vecSubClassShared;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com