Question1> 为什么下面的代码不起作用?
Question2> 正确的设计方法是什么?
#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;
}