我有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();
第二个示例的完整错误是:
Error: no suitable user-define conversion from "std::vector<error-type", std::alocator<<error-type> *>> "to " std::vector<Section*, std::allocator<Section*>>" exists
在我的项目的许多课程中,我无法执行第二行和第三行并收到相同的错误。我无法自己解释。请教我这个时候。
谢谢 :)