c++ 学习 one

类 和 对象  。

class Student{
private:
 string m_strName;


public :
   Student();
   Student(string name);
   Student(const Student &stu);
   ~Student();
   void setName(string name);
   string getName();
};


Student::Student(){
   cout<<" no params"<<endl;
}


Student::Student(string name){
         m_strName =name;
}
Student::Student(const Student &stu){
       cout<<" copy constuctor"<<endl;
}
Student::~ Student(){
        cout<<" ~ consturct"<<endl;
}
void Student::setName(string name){
         m_strName =name;
}
string Student::getName(){
         return m_strName;
}


int main(int argc, char* argv[])



Student *st1 = new Student();
string s="Jack";
Student stu(s);
st1->setName(s);
string st1Reslut=st1->getName();
cout<<st1Reslut<<endl;
Student st2(stu);
cout<<"uuu"+st2.getName()<<endl;
delete st1;

return 0;

}

出现 第一次错误,由于自动的弹出getName 函数 没有加 () 出现错误:

integral size mismatch in argument; conversion supplied 错误


第二次错误 在cout 里面输出字符串 提示不匹配, 引入有 <string.h> 但是不管有,引入 <string >  可以 

无参构造  有参构造  拷贝函数构造  

构造函数的 函数列表 ,可以初始化const 的属性的 值;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值