-1
誰能幫我檢查我的「class :: data member is private」錯誤。「class :: data member is private」error
#include <iostream>
using namespace std;
class Marks
{
private:
char * name;
char * grade;
float gpa;
public:
char* set_name(char * n)
{
name=n;
cout<<"Enter name :";
cin>>name;
return name;
}
float set_gpa(float g)
{
gpa=g;
cout<<"Enter CGPA :";
cin>>gpa;
return gpa;
}
char set_grade()
{
if(gpa>=3.00&&gpa<=4.00)
{
grade[1]='A';
}
else if(gpa>=2.00&&gpa<=2.99)
{
grade[1]='B';
}
else if(gpa>=0.00&&gpa<=1.99)
{
grade[1]='F';
}
else
{
cout<<"error"<<endl;
}
return grade[1];
}
}M1;
int main()
{
char name[20];
char grade[1];
float gpa;
cout<<"=================================="<<endl;
cout<<" ENTER INFORMATION "<<endl;
cout<<"=================================="<<endl;
M1.set_name(name);
M1.set_gpa(gpa);
M1.set_grade();
cout<<"=================================="<<endl;
cout<<" RESULT SLIP "<<endl;
cout<<"=================================="<<endl;
cout<<"Name : "<<M1.name;
cout<<"GPA : "<<M1.gpa;
cout<<"Grade : "<<M1.grade;
return 0;
}
錯誤列表
In function 'int main()':|
Line 9|error: 'char* Marks::name' is private|
Line 85|error: within this context|
Line 11|error: 'float Marks::gpa' is private|
Line 86|error: within this context|
Line 10|error: 'char* Marks::grade' is private|
Line 87|error: within this context|
Line 70|warning: unused variable 'grade'|
||=== Build finished: 6 errors, 1 warnings ===|
此問題似乎是無關緊要的,因爲它是關於在代碼轉儲中查找錯誤的。 SO不是調試服務。 –
這裏:'cout <<「名稱:」<< M1.name;'。您正在訪問'name'成員變量,儘管它是私人的。 –