假设我有
#include <string>
#include <vector>
using namespace std;
struct Student
{
const string name;
int grade;
Student(const string &name) : name(name) { }
};
那么,我如何保留学生的向量呢?
int main()
{
vector<Student> v;
// error C2582: 'operator =' function is unavailable in 'Student'
v.push_back(Student("john"));
}
有没有办法做到这一点,或者我必须在堆上分配所有学生,并存储一个指向他们每个人的指针?