看板Programming
标 题c++内如何得到物件的名称呢?
发信站KKCITY (Sat Jul 7 13:34:36 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!news.au!zoonews.ee.ntu!news
请教一下,这里我会产生两个物件,
只是,我希望在建构子内,看到物件的名称,
请问该如何做呢?
我使用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
》──┘※※ 内容丰富多元的线上音乐台 ※※
--