#include <iostream>
#include <string.h>
using namespace std;

class testwork
{
    public:
        testwork(string s)//constructor
        {
            p_s = s;
        }
        void Print_String()
        {
            cout<<"Constructor: "<<p_s<<endl;
        }
    private:
        string p_s;
};

int main()
{
    string s;
    cout<<"Enter a sentence: ";
    getline(cin,s);

//在main當中,資料初值、輸入、建立要和object分開,儲存和執行不要混在一起;如此一來才方便用相同資料做不同object

    testwork obj01(s);//constructor
    obj01.Print_String();
    return 0;
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Kuihao 的頭像
    Kuihao

    溫暖午後的金針田__孕育有趣的創新

    Kuihao 發表在 痞客邦 留言(0) 人氣()