64,654
社区成员
发帖
与我相关
我的任务
分享
41: cout << &a <<endl;
004017D8 push offset @ILT+205(std::endl) (004010d2)
004017DD push 1
004017DF mov ecx,offset std::cout (004767e0)
004017E4 call @ILT+40(std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040102d)
004017E9 mov ecx,eax
004017EB call @ILT+485(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004011ea)
#include <iostream>
using namespace std;
class A
{
public:
static void g()
{
cout << &a <<endl;
cout << &b <<endl;
cout << (void*)&c <<endl;
cout << &d <<endl;
}
private:
static int a,b;
static char c;
static int d;
};
int A::a = 0;
int A::b = 0;
char A::c = 0;
int A::d = 0;
void main()
{
A::g();
}
/*
输出为:
0047673C
00476740
00476744
00476748
Press any key to continue
注意char变量的地址先转换为void*,不然按照字符串输出,cout如果想输出地址,转换为void*即可
*/
#include <iostream>
#include <malloc.h>
using namespace std;
class A
{
public:
static void g()
{
cout <<&a <<endl; //输出变量地址
cout <<&b <<endl; //输出变量地址
cout <<&c <<endl; //其实不应该这么调用,能通过编译,感觉是骗过了编译器,钻空子而已
cout <<&d <<endl; //同上
}
private:
static int a,b;
char c;
int d;
};
int A::a=0;
int A::b=0;
void main()
{
A::g();
}