We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,272 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

error C2679 in class member initialization

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");

}
2
Contributors
1
Reply
5 Minutes
Discussion Span
2 Years Ago
Last Updated
2
Views
hero0765
Newbie Poster
1 post since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You most likely have to include <string> header file

Ancient Dragon
Achieved Level 70
Team Colleague
32,140 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0583 seconds using 2.69MB