For some reason, I keep getting error C2143: syntax error : missing ';' before '.'Code:student::student(string name,float g) { cout <<"student constructor is running..." <<endl; student.sname=name; //problem line gpa=g; }
Here's the full code:
Code:#include <iostream> #include <string> using namespace std; class student { public: string sname; float gpa; student(string name); student(string name,float g); ~student(); void display(); private: string name; float g; }; student::student(string name,float g) { cout <<"student constructor is running..." <<endl; student.sname=name; gpa=g; } student::student(string name) { cout <<"student constructor is running..." <<endl; student.sname=name; gpa = 0.0; } student::~student() { //cout <<"Student No.: "<<i<<endl; (Is there any way to use a variable as argument here?) cout <<"student destructor is running..." <<endl; } void student::display() { string sname; float gpa; cout <<"Student Name:" <<sname <<endl; //sname private cout <<"Student GPA:" <<gpa <<endl; //gpa private }



LinkBack URL
About LinkBacks



