=D5=C5=D6=BE=B8=D5 wrote:
#include "stdio.h"
Prefer <cstdio>
#include "conio.h"
Non standard.
class INT
Reserve all-uppercase names to macros.
{
public:
int p;
INT(int a):p(a){printf("%d.p=3D %d\r\n",(int)this,p);}
Some formatting would be appreciated. You don't need to write "\r\n" to
get a newline, just "\n" will do.
};
class C
{
public:
INT c;
C():c(0){}
C(int a):c(a){ C(); }
I'm not sure this does what you expect. It dosen't "call" C's default
constructor (which means you cannot in C++ "chain" constructor calls as
Java or C# does), it creates an unnamed object of type C, which is
destroyed right at the semicolumn. This is the same as
C(int a)
: c(a)
{
C temp;
}
};
void main()
main() returns an int. Always.
{
C cc(9);
printf("%d.c=3D%d\r\n",(int)&cc,cc.c.p); //how many is this p =A3=BF9=A3=
=BF0=A3=BF
getch();
getch() is non standard.
}
look at the result printed:
1245052.p=3D 9
1244956.p=3D 0
1245052.c=3D9
the result of c is 9. why are there to address of p? 1245052.p=3D 9
1244956.p=3D 0
The second "p" you see is the one created in C's constructor. Remove
the "C()" bit and the "problem" will go away.
Jonathan
.