Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

CµÄº¯ÊýÖ¸ÕëʵÏÖC++µÄ¶à̬

CµÄº¯ÊýÖ¸ÕëºÜÇ¿´ó£¬ÓúÃÁ˲ÅÊÇCÓïÑԵĸßÊÖ¡£ÏñGtkÖеĻص÷º¯ÊýµÄʹÓ㬶¼ÌåÏÖÁ˺¯ÊýÖ¸ÕëµÄÇ¿´óÍþÁ¦¡£
struct Point{
int x, y;
};
/*Shape*/
/*----------------------------------------------------------------*/
struct Shape {
struct Methods* methods;
};

struct Methods {//½«C++¶ÔÓ¦ÀàÖÐËùÓгÉÔ±º¯Êý·â×°µ½Ò»¸ö½á¹¹ÌåÀïÃæ
float (*getCircle)(Shape * shape);
float (*getArea)(Shape * shape);
void (*draw)(Shape * shape);
void (*move)(Shape * shape);
};
////////////////C++ Counterpart of above code//////////////////
class Shape {
public:
virtual float getCircle() = 0;
virtual float getArea() = 0;
virtual void draw() = 0;
virtual void move() = 0;
};
///////////////////////////////////////////////////////////////
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/*Rectangle*/
struct Rectangle {
struct Methods * methods; //°üº¬·â×°ºóµÄ³ÉÔ±º¯Êý½á¹¹ÌåµÄÖ¸Õë
Point leftTop; //ShapeÖ®ÍâÅÉÉúµÄ³ÉÔ±±äÁ¿
Point rightBottom; //ShapeÖ®ÍâÅÉÉúµÄ³ÉÔ±±äÁ¿
};
float Rectangle_getCircle(Shape * shape)
{
Rectangle * r = (Rectangle *) shape;
return (r->rightBottom.x - r->leftTop.x +
r->rightBottom.y - r->leftTop.y) * 2;
}
float Rectangle_getArea(Shape * shape){}
void Rectangle_draw (Shape * shape){}
void Rectangle_move(Shape * shape){}
struct Methods rectangleMethods = {
&Rectangle_getCircle,
&Rectangle_getArea,
&Rectangle_draw,
&Rectangle_move,
};
////////////////C++ Counterpart of above code//////////////////
class Rectangle : public Shape {
Point leftTop;
Point rightBottom;
public:
virtual float getCircle();
virtual float


Ïà¹ØÎĵµ£º

C/C++ÔËËã·ûµÄÓÅÏȼ¶


Precedence Operator Description Example Overloadable Associativity
1
::
Scope resolution operator
Class::age = 2;
no
none
2
()
()
[]
->
.
++
--
const_cast
dynamic_cast
static_cast
reinterpret_cast
typeid
Function call
Member initalization
Array access
Member access from ......

¶Ô¶þ¼¶cµÄÎÞÓï(Öйúʽ¿¼ÊÔ!!)

×î½üÔÚcsdnµÄÂÛ̳ÉÏ·¢ÁËÕâÑùÒ»¸öÌû×ÓÈçÏÂ
int a=5;
a*=a/=a++;
ÎÒÔÚÒ»±¾¶þ¼¶cµÄÊéÉÏ¿´µ½µÄ´ð°¸ÊÇ2 ÓÉÓÚÎÒ¶Ô´ËÌâ²¢²»ÊÇÊ®·ÖÀí½â ËùÒÔÔÚÂÛ̳ÉÏ·¢±í ¿´ÓÐûÓÐÈËÄܰï׎âÊÍһϠȴûÓÐÏëµ½ÒýÀ´µÄ40¶àÂ¥µÄÒ»¸ö³¤Ìù ÒÔÖÁÓÚµ½×îºóÌÖÂÛµÄÄÚÈÝÔ¶Ô¶³¬¹ýµÄÌâÄ¿±¾Éí ÕæÊµ²»½â,ΪʲôÕâôÓÐÕùÒéµÄÌâÈ´ÄÃÀ´¿¼ÈË,Äѵ½¶¼Òª°´¶þ¼¶cµÄvc±àÒ ......

½â¶Á¸´ÔÓµÄC/C++ÉùÃ÷[ʵսƪ]

ÕâÊÇÈëÃÅÆªÖÐÌáµ½µÄÄÇÁ½Ì⣺
int * (* (*fp1) (int) ) [10];
int *( *( *arr[5])())();
½â´ðÈçÏÂ
1.int * (* (*fp1) (int) ) [10];
´ÓÍâÍùÄÚ½øÐзÖÎö
a.typedef P=(* (*fp1) (int) )£¬ÄÇôԭÉùÃ÷¸ÄдΪ int*P[10]£¬ÕâÊÇÒ»¸öÓÐ10¸öÔªËØµÄÊý×飬ÿ¸öÔªËØ¶¼ÊÇÒ»¸öÖ¸ÏòÕûÐÍÊýµÄÖ¸Õë
b.typedef Q=(*fp1)£¬ÄÇôP¸ÄдΪ *Q( ......

c/c++ÄÚ´æ»®·Ö

Ò»¡¢Ò»¸ö¾­¹ý±àÒëµÄC/C++µÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·Ö³ÉÒÔϼ¸¸ö²¿·Ö£º
¡¡¡¡1¡¢Õ»Çø£¨stack£©£ºÓɱàÒëÆ÷×Ô¶¯·ÖÅäºÍÊÍ·Å £¬´æ·Åº¯ÊýµÄ²ÎÊýÖµ¡¢¾Ö²¿±äÁ¿µÄÖµµÈ£¬ÉõÖÁº¯ÊýµÄµ÷Óùý³Ì¶¼ÊÇÓÃÕ»À´Íê³É¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£
¡¡¡¡2¡¢¶ÑÇø£¨heap£© £ºÒ»°ãÓɳÌÐòÔ±ÊÖ¶¯ÉêÇëÒÔ¼°ÊÍ·Å£¬ Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøÊ±¿ÉÄÜÓÉOS»ØÊÕ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ