C++??????????D???
???????????? ???????[ 2014/7/1 11:38:29 ] ????????C++ net
????????
????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 ?????????????????з???????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11