标签:
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 class Golf 5 { 6 string m_name; 7 int m_handicap; 8 public: 9 Golf():m_name("Sam"),m_handicap(24){};//析构函数的赋值,m_name和m_handicap在进入大括号之前就已经初始化 10 void show() 11 { 12 cout << m_name << ‘,‘ << m_handicap <<endl; 13 } 14 Golf( string name,int handicap) 15 { 16 m_name = name; 17 m_handicap = handicap; 18 } 19 20 }; 21 int main() 22 { 23 Golf one; 24 Golf two("Tonny",10086); 25 one.show(); 26 two.show(); 27 } 28
直接用string就好了,前面试着用strcpy赋值很麻烦。
标签:
原文地址:http://www.cnblogs.com/fudianheg/p/4234942.html