c++內如何得到物件的名稱呢?
請教一下,這裡我會產生兩個物件,
只是,我希望在建構子內,看到物件的名稱,
請問該如何做呢?
我使用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 》──┘※※ 內容豐富多元的線上音樂台 ※※
--
討論串 (同標題文章)
完整討論串 (本文為第 1 之 4 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章