stavo leggendo quanto riguarda costruttore movimento e ho fatto questo codice in VS 2013 ...Spostare Constructor - tipo non valido per il costruttore di default VS 2013
class Student
{
unique_ptr<string> pName_;
public:
Student(string name) : pName_(new string(name)) { }
~Student() { }
Student(Student&&) = default; // Here I get the error.
void printStudentName(void) { cout << *pName_ << endl; }
};
int main(void)
{
vector<Student> persons;
Student p = Student("Nishith");
persons.push_back(std::move(p));
persons.front().printStudentName();
return 0;
}
ho la "Student::Student(Student&&)
: non è una funzione membro speciale che può essere predefinito "quando ho provato a compilarlo ...
Qualcuno può spiegarmi perché sto ottenendo questo errore?
Meglio anche aggiungere il tag di base C++. Ad ogni modo, sai che usare l'allocazione dinamica per la stringa è uno spreco completo? – Deduplicator
Intendevi nello studio visivo, giusto? – Deduplicator
@Deduplicator: Ok, punto preso. Sì, intendevo Visual Studio 2013. – NJMR