私はclass Student
( studentOwner
) とを持っていclass Section
ます。これが私のクラスStudent
です:
class Student {
vector<Section*> enrolledSections;
public:
vector<Section*> getEnrolledSections() const { return enrolledSections; }
}
そのため、別のベクトルを取得vector<Section*>
して割り当てると、エラーが発生します。Microsoft Visual Studio を使用しています。
// first example: no error, if take size of vector
int a = studentOwner->getEnrolledSections().size();
// second example: error, when only take its vector and assign again
// Error: no suitable user-define conversion from "std::vector<error-type" ....
vector<Section*> enrolled = studentOwner->getEnrolledSections();
// third example: error when take this vector and assign to reference of same type
// Error: initial value of reference to non-const value must be lvalue
vector<Section*>& enrolled = studentOwner->getEnrolledSections();
2 番目の例の完全なエラーは次のとおりです。
Error: no suitable user-define conversion from "std::vector<error-type", std::alocator<<error-type> *>> "to " std::vector<Section*, std::allocator<Section*>>" exists
私のプロジェクトの多くのクラスで、2行目と3行目を実行できず、同じエラーが発生しました。自分では説明できません。この際教えてください。
ありがとう :)