我来说句公道话,其实老师写的并没有错,5.30分,像一楼所说的,应该写成p[i].type和p[i].changeVol()!,其实是一楼写的是错的, 要是用“.”这个运算符,应该写成的是TV[1].type或 p[i]->type ,而不是p[i].type p是指针,并不和点这个运算符配用的,,所以大家不要误会,老师讲的并没有错,要是有疑问也可以留言我,我会回复。。
2018-04-18
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
string m_strName;
string m_iAge;
};
int main()
{
Student stu;
stu.m_strName = "慕课网";
stu.m_iAge = 2;
cout << stu.m_strName<< " " <<stu.m_iAge<< endl;
return 0;
}
#include <string>
using namespace std;
class Student
{
public:
string m_strName;
string m_iAge;
};
int main()
{
Student stu;
stu.m_strName = "慕课网";
stu.m_iAge = 2;
cout << stu.m_strName<< " " <<stu.m_iAge<< endl;
return 0;
}
他的意思是让private称为一个中间量让setname里面的值流入getname函数然后在输出调用吗?
public:
string setname(string sname)
{ m_strName = sname;
return sname; }
string getname()
{ string gname;
gname = m_strName;
return gname;}
private:
string m_strName;};
public:
string setname(string sname)
{ m_strName = sname;
return sname; }
string getname()
{ string gname;
gname = m_strName;
return gname;}
private:
string m_strName;};