1.為什么我運行后還會出來一個地址的值,這個是哪里冒出來的... 2.我想輸出this指針的地址,為什么在main函數下 cout<<this<<endl;或者cout<<arr1.this<<endl;就會提示出現錯誤?想要在main函數下cout this指針地址應該怎么弄?
#include "iostream"
using namespace std;
#include "stdlib.h"
class Array
{?
public:
Array(int len )
{
this->len=len;
}
~Array()
{
}
Array *setLen(int len)
{
this->len=len;
return this;
}
int ?getLen()
{
return len;
}
Array*printInfo() ?
{ ? ?
cout<<"Len="<<len<<endl;
return this;
} ?
private:
int len;
};
int main()
{
Array arr1(10);
cout<<arr1.printInfo()<<endl;
system("pause");
return 0;
}
2015-12-21
this 指針時能在 class 定義內部使用,main 函數中不可見 this 指針。
2015-09-11
Array*printInfo() ?
{ ? ?
cout<<"Len="<<len<<endl;
return this;
} ?
注意return *this ?你沒有注意返回值
2015-08-13
private可以在類作用域內訪問,域外通過pubilc成員函數訪問