1.11M Members

error C2679 in class member initialization

 
0
 

hi:
I have a trouble on the codes below, if I were to insert string n into the following string "Constructing student" ,the compile would appear error C2679. I don't know where any error the code have.

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

#include<iostream>

using namespace std;

class StudentID{

    int value;

public:
	StudentID(){

     static int nextStudentID = 0;
	 value = ++nextStudentID;
	 cout << "Assigning student id "<<value<<endl;

	}


};

class Student{

    string name;
	StudentID id;

public:
	Student(string n = "noName"){
     cout << "Constructing student " <<n<<endl; //error C2679
	 name = n;
	 

	}


};

void main(){
    
	Student s("Randy");

}
 
0
 

You most likely have to include <string> header file

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: