为了账号安全,请及时绑定邮箱和手机立即绑定
Student() {
cout << "Student()" << endl;
}
explicit Student(string name) {
m_strName = name;
cout << "Student(string name)" << endl;
}
Student(const Student& stu) {
cout << "Student(const Student& stu)" << endl;
}
int main(void)
{
Student *stu = new Student("张晨飞");
Student *stu1 = new Student("张晨飞");
Student *stu2(stu1);
stu->setName("慕课网");
cout<<"学生名字:"<<stu->getName()<<endl;
cout<<"学生名字:"<<stu2->getName()<<endl;
delete stu2,stu,stu1;
stu=stu1=stu2=NULL;
return 0;
}
必须得把慕课网放到第一个输出
class Student
{
public:
Student(){}
Student(string _name){m_strName=_name;}
Student(const Student& stu){}
~Student(){}
void setName(string _name){m_strName=_name;}
string getName(){return m_strName;}
private:
string m_strName;
};
/* copyright */
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
class Student {
public:
void setName(string _name) {
m_strName = _name;
}
string getName() {
return m_strName;
}
private:
string m_strName;
};
#include <iostream>
#include <string>
using std::cout;
using std::endl;

namespace Student {
public:
int m_strName;
int m_iAge;
};
int main(void) {
Student stu;
stu.m_strName = "imooc";
stu.m_iAge = 2;
cout << stu.m_strName << " " << stu.m_iAge << endl;
return 0;
}

最新回答 / 慕粉1213598641
由于是用指针p申请的堆内存,所以在调用成员时该用p[n]->

已采纳回答 / 慕粉1213598641
括号是向TV类传参数用的,如果TV类写了带有参数的构造函数,那么括号中就该写上对应的参数。
把 system("pause")去掉就看到了
讲的很好(✪▽✪)
这个正确的判定对比也是坑

最赞回答 / 点颗许愿烟0
for(int i=0; i<n; i++){//n的值为你的姓的字母个数减1    cout << name[i];//从第一个字母开始循环输出}cout << endl;//结束换行
老师讲的真好,比某些培训机构的老师好多了
快来看剧透啊
讲的很好!!
public:
void setName(string _name)
{m_strName = _name;}
string getName()
{return m_strName;}
private:
string m_strName;
};

int main()
{ Student *str = new Student();
str-&gt;setName(&quot;慕课网&quot;);
cout &lt;&lt; str-&gt;getName() &lt;&lt;endl;
delete str;
str = NULL;
return 0;}

最新回答 / Mirror丨镜子
堆中对象调用了setName函数
课程须知
本课程是C++初级课程 需要熟练掌握C++语言基础语法
老师告诉你能学到什么?
1、类的定义与对象实例化 2、string类型及属性封装 3、类外定义 4、构造函数与初始化列表 5、析构函数

微信扫码,参与3人拼团

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消