看板 Programming 關於我們 聯絡資訊
請教一下,這裡我會產生兩個物件, 只是,我希望在建構子內,看到物件的名稱, 請問該如何做呢? 我使用this,可是卻顯示出記憶體位址.. 謝謝.. 附上原始碼如下: #include <iostream> using namespace std; class spot { private: //int px,py; public: int px,py; spot(); void setspot(int,int); void display(); }; spot::spot() {px=0; py=0; cout<<this<<"create!"<<endl; } void spot::setspot(int x,int y) { px=x; py=y; } void spot::display() { cout<<"x座標為"<<px<<endl; cout<<"y座標為"<<py<<endl; } int main() { spot one,two; one.setspot(30,40); cout<<"one is"; one.display(); two.setspot(20,50); cout<<"two is"; two.display(); system("PAUSE"); return 0;} -- ┌─────KKCITY─────┐KKMAN團隊 全新力作 ◎◎KKBOX◎◎ bbs.kkcity.com.tw 知名歌手通通都有 所有新歌想聽就聽 └──From:140.109.139.90 ──┘※※ 內容豐富多元的線上音樂台 ※※ --