C++ 类声明后的标识符做什么? 类号 { int x,y; 公众: void get()/(数字*此常量) { coutthis->x; //cin>>x; coutthis->y; } 无效显示() { cout
它是类C++ 类声明后的标识符做什么? 类号 { int x,y; 公众: void get()/(数字*此常量) { coutthis->x; //cin>>x; coutthis->y; } 无效显示() { cout,c++,class,C++,Class,它是类NUMBER变量的即时声明。 这相当于: class NUMBER { int x,y; public: void get()//(NUMBER *this const) { cout<<"\n Enter value for x:"; cin>>this->x; //cin>>x; cout<<"\n Enter va
NUMBER
变量的即时声明。
这相当于:
class NUMBER
{
int x,y;
public:
void get()//(NUMBER *this const)
{
cout<<"\n Enter value for x:";
cin>>this->x;
//cin>>x;
cout<<"\n Enter value for y:";
cin>>this->y;
}
void display()
{
cout<<"\n x is::"<<x;
cout<<"\n y is::"<<y;
cout<<"\n address of called object is:"<<this;
}
}n3;
它是
类号
的一个实例名n3
。无关:不要使用大写的类名。当你对编译器大喊大叫时,编译器会感到悲伤。当你发布不是你自己写的代码时,说它是从哪里来的是一种很好的风格。它是否还为其他任何事情留下了类定义?很明显,如果我写了类号{…};编号n3;编号n4;
我会有两个NUMBER
实例。我可以在原始问题中的代码后面写NUMBER n4;
吗?可以
class NUMBER { ... };
NUMBER n3;