????????
????C++ ????
???????? C++ ?ü????????????????????????
????struct A x?? y;
????...
????x = y;
??????????????????????????????????????????????????????
????#include <string.h>
????struct A x?? y;
????inline bool operator==(const A& x?? const A& y)
????{
????return (memcmp(&x?? &y?? sizeof(struct A)) == 0);
????}
????...
????if (x == y)
????...
???????????????????????????????????????????????????????????????????е?????????????顣C++ ????????????????????????? (x == y) ???????????????ò?????????????? operator==() ??????????????Щ????
????????? operator==() ????? memcmp() ?????????????a?? bug ????????????????????????????????????????п??????“??”??C++ ?????????Щ??????????е???????????????????????????????????????????????????????к??в????????????????
????????????????operator==() ???????????????memberwise???????????????????????????? (1) ??????????????????????У???????????????????????? operator==() ?У?(2) ??????????? nan ?????????????λ????????????????????
?????? C++ ????н????????????
????D ????
????D ?????????????
????A x?? y;
????...
????if (x == y)
????...
?????????μ? typedef ???
????C++ ????
????Typedef ?? C++ ?????????????????????????????????μ?????????????????? typedef ???????????
????#define HANDLE_INIT ((Handle)(-1))
????typedef void *Handle;
????void foo(void *);
????void bar(Handle);
????Handle h = HANDLE_INIT;
????foo(h);   // δ?????????????
????bar(h);   // ok
????C++ ?????????????????????dummy?????????????????????????????????????е?????????????????

 

????#define HANDLE_INIT ((void *)(-1))
????struct Handle
????{   void *ptr;
????Handle() { ptr = HANDLE_INIT; } // default initializer
????Handle(int i) { ptr = (void *)i; }
????operator void*() { return ptr; } // conversion to underlying type
????};
????void bar(Handle);
????Handle h;
????bar(h);
????h = func();
????if (h != HANDLE_INIT)
????...

????D ????
????????????????????????????????д??
????typedef void *Handle = cast(void *)-1;
????void bar(Handle);
????Handle h;
????bar(h);
????h = func();
????if (h != Handle.init)
????...
???????????? typedef ??????????????????????????
???????
????C++ ????
???????????????????????????????й????????????????????????????г?????? C++ ????????? friend ??????

 

class A
{
private:
int a;
public:
int foo(B *j);
friend class B;
friend int abc(A *);
};
class B
{
private:
int b;
public:
int bar(A *j);
friend class A;
};
int A::foo(B *j) { return j->b; }
int B::bar(A *j) { return j->a; }
int abc(A *p) { return p->a; }

????D ????
?????? D ?У?λ????????????????????????????????????????е?????????????????????λ??????????У?????????????λ??????????е?????????????????????????

 

module X;
class A
{
private:
static int a;
public:
int foo(B j) { return j.b; }
}
class B
{
private:
static int b;
public:
int bar(A j) { return j.a; }
}
int abc(A p) { return p.a; }

????private ?????????????????з???????