c++ 学习 one

来源:互联网 发布:哪个软件播放rmvb 编辑:程序博客网 时间:2024/05/18 13:27

类 和 对象  。

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