#include?<iostream>??
#include?<string>
using?namespace?std;
?/**
??*?定義類:Student
??*?數(shù)據(jù)成員:m_strName
??*?數(shù)據(jù)成員的封裝函數(shù):setName()、getName()
??*/
class?Student
{
public:
????void?setName(string?_name)??????????????//?定義數(shù)據(jù)成員封裝函數(shù)setName()
{
????m_strName=_name;
}???
string?getName()????????????????????????????//?定義數(shù)據(jù)成員封裝函數(shù)getName()
{
????return?m_strName;
}????
????
private:
string?m_strName;???????????????????????????//定義Student類私有數(shù)據(jù)成員m_strName
};
int?main()
{
????Student?*str?=?new?Student;?????????????//?使用new關(guān)鍵字,實例化對象
????
?str->setName("niko?bellic");?????????????????//?設置對象的數(shù)據(jù)成員
???
????
????
?cout<<str->setName()<<endl;?????????????//?使用cout打印對象str的數(shù)據(jù)成員
?delete?str??????????????????????????????//?將對象str的內(nèi)存釋放,并將其置空
????str?=NULL;
????return?0;
}
2022-03-29
這是個element對象呀
cxtpnzlbkhpxhcjxwowwouenepmrqxpzibdtslzfizzuugtrbatjhkuxxsmgivyexszuptdbtcwanvtkbai
2016-11-07
你的代碼倒數(shù)第五行應該把setName()改成getName()