??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产一区二区三区不卡 ,无码国内精品久久人妻麻豆按摩,久久久久无码精品国产http://www.shnenglu.com/iuranus/category/4275.html<br><font color="#ADFF2F">Something DifferentQSomething New</font>zh-cnThu, 06 May 2010 09:44:37 GMTThu, 06 May 2010 09:44:37 GMT60(?C++E序调用C函数http://www.shnenglu.com/iuranus/archive/2010/03/08/109187.html攀?/dc:creator>攀?/author>Mon, 08 Mar 2010 07:23:00 GMThttp://www.shnenglu.com/iuranus/archive/2010/03/08/109187.htmlhttp://www.shnenglu.com/iuranus/comments/109187.htmlhttp://www.shnenglu.com/iuranus/archive/2010/03/08/109187.html#Feedback0http://www.shnenglu.com/iuranus/comments/commentRss/109187.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/109187.html转自Q?a >http://blog.csdn.net/ustcgy/archive/2009/12/23/5063082.aspx

q种需求很?又因为C++和C是两U完全不同的~译链接处理方式,所以要E加处理.ȝ大致有两大类实现Ҏ(gu).

文中l出的是完整?具体?但又最基本最单的实现,至于理论性的东西在网上很Ҏ(gu)搜烦的到.

一.通过处理被调用的C头文?/strong>

a.h:

#ifndef __A_H
#define __A_H

#ifdef __cplusplus
extern "C" {
#endif

int ThisIsTest(int a, int b);

#ifdef __cplusplus
}
#endif

#endif

a.c:

#include "a.h"

int ThisIsTest(int a, int b) {
  return (a + b);
}

aa.h:

class AA {
  public:
      int bar(int a, int b);
};

aa.cpp:

#include "a.h"
#include "aa.h"
#include "stdio.h"

int AA::bar(int a, int b){
    printf("result=%d\n", ThisIsTest(a, b));
    return 0;
}

main.cpp:

#include "aa.h"

int main(int argc, char **argv){
  int a = 1;
  int b = 2;
  AA* aa = new AA();
  aa->bar(a, b);
  delete(aa);
  return(0);
}

Makefile:

all:
        gcc -Wall -c a.c -o a.o
        gcc -Wall -c aa.cpp -o aa.o
        gcc -Wall -c main.cpp -o main.o
        g++ -o test *.o

? 通过处理调用的C++文g

恢复a.h文gZ般性C头文?在aa.cpp文g中extern包含a.h头文件或函数.

a.h:

#ifndef __A_H
#define __A_H
int ThisIsTest(int a, int b);
#endif

aa.cpp:

extern "C"
{
    #include "a.h"
}
#include "aa.h"
#include "stdio.h"

int AA::bar(int a, int b){
    printf("result=%d\n", ThisIsTest(a, b));
    return 0;
}

or

aa.cpp:

#include "aa.h"
#include "stdio.h"

extern "C"
{
    int ThisIsTest(int a, int b);
}

int AA::bar(int a, int b){
    printf("result=%d\n", ThisIsTest(a, b));
    return 0;
}



]]>
(? ȝC++中的所有强制{换函?const_castQreinterpret_castQstatic_castQdynamic_cast) http://www.shnenglu.com/iuranus/archive/2009/06/22/88257.html攀?/dc:creator>攀?/author>Mon, 22 Jun 2009 03:24:00 GMThttp://www.shnenglu.com/iuranus/archive/2009/06/22/88257.htmlhttp://www.shnenglu.com/iuranus/comments/88257.htmlhttp://www.shnenglu.com/iuranus/archive/2009/06/22/88257.html#Feedback6http://www.shnenglu.com/iuranus/comments/commentRss/88257.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/88257.html
非常抱歉Q谢谢郭老师的指正,我没有认真看q个文章p{q来了,其实他的错误太多了,而且q是致命的,对大家不负责MQ请大家谅解Q现在是修正版本Q基本没有错误了Q如果觉得还有问题,误pLQ谢谢你的关注!
q篇文章其实q不是不才的原创Q本来打自己写的,但是通过baidu一下,发现有兄弟写出来了,干脆摘录下来,供大家参考用了Q?br>详情L(fng)Q?br>
  1. 标准c++中主要有四种强制转换cdq算W:(x)  
  2.   
  3. const_castQreinterpret_castQstatic_castQdynamic_cast{等?nbsp; 
  4.   
  5.   
  6.   
  7.   
  8. 1Qstatic_cast<T*>(a)  
  9.   
  10. 地址a转换成类型TQT和a必须是指针、引用、算术类型或枚Dcd?nbsp; 
  11.   
  12. 表达式static_cast<T*>(a), a的D{换ؓ(f)模板中指定的cdT。在q行时{换过E中Q不q行cd查来保转换的安全性?nbsp; 
  13.   
  14.   
  15.   
  16.   
  17. 例子Q?nbsp; 
  18.   
  19.   
  20.   
  21.   
  22. class B { ... };  
  23.   
  24. class D : public B { ... };  
  25.   
  26. void f(B* pb, D* pd)  
  27.   
  28. {  
  29.   
  30.    D* pd2 = static_cast<D*>(pb);        // 不安? pb可能只是B的指?nbsp; 
  31.   
  32.   
  33.   
  34.   
  35.    B* pb2 = static_cast<B*>(pd);        // 安全?nbsp; 
  36.   
  37.    ...  
  38.   
  39. }  
  40.   
  41.   
  42.   
  43.   
  44.   
  45.   
  46.   
  47. class B { ... };  
  48.   
  49. class D : public B { ... };  
  50.   
  51. void f(B* pb, D* pd)  
  52.   
  53. {  
  54.   
  55.    D* pd2 = static_cast<D*>(pb);        // 不安? pb可能只是B的指?nbsp; 
  56.   
  57.   
  58.   
  59.   
  60.    B* pb2 = static_cast<B*>(pd);        // 安全?nbsp; 
  61.   
  62.    ...  
  63.   
  64. }  
  65.   
  66.   
  67.   
  68.   
  69.   
  70.   
  71.   
  72. class B { ... };  
  73.   
  74. class D : public B { ... };  
  75.   
  76. void f(B* pb, D* pd)  
  77.   
  78. {  
  79.   
  80.    D* pd2 = static_cast<D*>(pb);        // 不安? pb可能只是B的指?nbsp; 
  81.   
  82.   
  83.   
  84.   
  85.    B* pb2 = static_cast<B*>(pd);        // 安全?nbsp; 
  86.   
  87.    ...  
  88.   
  89. }  
  90.   
  91.   
  92.   
  93.   
  94. 2Qdynamic_cast<T*>(a)  
  95.   
  96. 完成cdơ结构中的提升。T必须是一个指针、引用或无类型的指针。a必须是决定一个指针或引用的表辑ּ?nbsp; 
  97.   
  98. 表达式dynamic_cast<T*>(a) aD{换ؓ(f)cd为T的对象指针。如果类型T不是a的某个基cdQ该操作返回一个空指针?nbsp; 
  99.   
  100.   
  101.   
  102.   
  103. 例子Q?nbsp; 
  104.   
  105. class A { ... };  
  106.   
  107. class B { ... };  
  108.   
  109. void f()  
  110.   
  111. {  
  112.   
  113.   A* pa = new A;  
  114.   
  115.   B* pb = new B;  
  116.   
  117.   void* pv = dynamic_cast<A*>(pa);  
  118.   
  119.   // pv 现在指向了一个类型ؓ(f)A的对?nbsp; 
  120.   
  121.   ...  
  122.   
  123.   pv = dynamic_cast<B*>(pb);  
  124.   
  125.   // pv 现在指向了一个类型ؓ(f)B的对?nbsp; 
  126.   
  127. }  
  128.   
  129.   
  130.   
  131.   
  132. 3Qconst_cast<T*>(a)  
  133.   
  134. Lcd中的帔RQ除了const或不E_的变址敎ͼT和a必须是相同的cd?nbsp; 
  135.   
  136. 表达式const_cast<T*>(a)被用于从一个类中去除以下这些属性:(x)const, volatile, ?nbsp;__unaligned?nbsp; 
  137.   
  138.   
  139.   
  140.   
  141. 例子Q?nbsp; 
  142.   
  143.   
  144.   
  145.   
  146.   
  147.   
  148.   
  149. class A { ... };  
  150.   
  151. void f()  
  152.   
  153. {  
  154.   
  155.  const A *pa = new A;//const对象  
  156.   
  157.  A *pb;//非const对象  
  158.   
  159.   
  160.   
  161.   
  162. //pb = pa; // q里出错,不能const对象指针赋值给非const对象  
  163.   
  164.  pb = const_cast<A*>(pa); // 现在OK?nbsp; 
  165.   
  166. ...  
  167.   
  168. }  
  169.   
  170.   
  171.   
  172.   
  173.   
  174.   
  175.   
  176. class A { ... };  
  177.   
  178. void f()  
  179.   
  180. {  
  181.   
  182.  const A *pa = new A;//const对象  
  183.   
  184.  A *pb;//非const对象  
  185.   
  186.   
  187.   
  188.   
  189. //pb = pa; // q里出错,不能const对象指针赋值给非const对象  
  190.   
  191.  pb = const_cast<A*>(pa); // 现在OK?nbsp; 
  192.   
  193. ...  
  194.   
  195. }  
  196.   
  197.   
  198.   
  199.   
  200.   
  201.   
  202.   
  203. class A { ... };  
  204.   
  205. void f()  
  206.   
  207. {  
  208.   
  209.  const A *pa = new A;//const对象  
  210.   
  211.  A *pb;//非const对象  
  212.   
  213.   
  214.   
  215.   
  216. //pb = pa; // q里出错,不能const对象指针赋值给非const对象  
  217.   
  218.  pb = const_cast<A*>(pa); // 现在OK?nbsp; 
  219.   
  220. ...  
  221.   
  222. }  
  223.   
  224.   
  225.   
  226.   
  227. 4Qreinterpret_cast<T*>(a)  
  228.   
  229. M指针都可以{换成其它cd的指针,T必须是一个指针、引用、算术类型、指向函数的指针或指向一个类成员的指针?nbsp; 
  230.   
  231. 表达式reinterpret_cast<T*>(a)能够用于诸如char* ?nbsp;int*Q或者One_class* ?nbsp;Unrelated_class*{类DL(fng)转换Q因此可能是不安全的?nbsp; 
  232.   
  233.   
  234.   
  235.   
  236. 例子Q?nbsp; 
  237.   
  238. class A { ... };  
  239.   
  240. class B { ... };  
  241.   
  242. void f()  
  243.   
  244. {  
  245.   
  246.   A* pa = new A;  
  247.   
  248.   void* pv = reinterpret_cast<A*>(pa);  
  249.   
  250.   // pv 现在指向了一个类型ؓ(f)B的对象,q可能是不安全的  
  251.   
  252.   ...  
  253.   




]]>
可以Ҏ(gu)字符串创建类?-解决Ҏ(gu) 熟练c/c++(?http://www.shnenglu.com/iuranus/archive/2009/01/12/71832.html攀?/dc:creator>攀?/author>Mon, 12 Jan 2009 14:29:00 GMThttp://www.shnenglu.com/iuranus/archive/2009/01/12/71832.htmlhttp://www.shnenglu.com/iuranus/comments/71832.htmlhttp://www.shnenglu.com/iuranus/archive/2009/01/12/71832.html#Feedback28http://www.shnenglu.com/iuranus/comments/commentRss/71832.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/71832.html想了很久Q结合c++设计新思维的方法,大家q种设计?x)有什么问题?


Q-Q-Q-Q-Q-QIShape.hQ-Q-Q-Q-Q-Q-Q-Q-Q?br>class IShape
{
public:
 IShape()
 {
  printf("\n IShape\n");
 }
 virtual ~IShape()
 {
  printf("\n ~IShape\n");
 }
 virtual void Draw() = 0;
};

typedef const char* ShapeType;
typedef IShape* (*Creator)();


Q-Q-Q-Q-Q-Q-ShapeFactory.hQ-Q-Q-Q-Q-Q-Q-Q-Q-Q-

class ShapeFactory {
public:
    static ShapeFactory& Instance() {
        static ShapeFactory instance;
        return instance;
    }

    IShape* Create(ShapeType shapeType);
    bool RegisterShape(ShapeType shapeType, Creator creator);

private:
    ShapeFactory() {}
 std::map<ShapeType, Creator> shapeCreators;
};

Q-Q-Q-Q-Q-Q-ShapeFactory.cppQ-Q-Q-Q-Q-Q-Q-Q-Q-Q-

#include "CFactory.h"

IShape* ShapeFactory::Create(ShapeType shapeType) {
      Creator creator = shapeCreators.find( shapeType )->second;
 
      if ( creator == NULL ) 
      { 
           return NULL; 
       }
       return creator();
}

bool ShapeFactory::RegisterShape( ShapeType shapeType, Creator creator ) {
       map<ShapeType, Creator>::iterator iter;
       iter = shapeCreators.find(shapeType);
       if(iter != shapeCreators.end())
       {
           return false;
       } else {
           shapeCreators[shapeType] = creator;
           return true;
    }
}

Q-Q-Q-Q-Q-Q-CCircle .hQ-Q-Q-Q-Q-Q-Q-Q-Q-Q-
#include<stdio.h>

#include "IShape.h"
#include "CFactory.h"
class CCircle : public IShape
{
public:
 CCircle()
 {
  printf("\n CCircle\n");
 }
 virtual ~CCircle()
 {
  printf("\n ~CCircle\n");
 }

 virtual void Draw();
};


Q-Q-Q-Q-Q-Q-CCircle .cppQ-Q-Q-Q-Q-Q-Q-Q-Q-Q-
#include "CCircle.h"

IShape* Create() { return new CCircle(); }
static const bool RegisterShape__ = ShapeFactory::Instance().RegisterShape( "CCircle", Create);

void CCircle::Draw()
{
 printf("\n CCircle::Draw\n");
}


Q-Q-Q-Q-Q-Q-main.cppQ-Q-Q-Q-Q-Q-Q-Q-Q-Q-
#include<stdio.h>
#include"CFactory.h"

#include "IShape.h"

int main() {
    IShape* line = ShapeFactory::Instance().Create("CCircle");
    line->Draw();    
    return 0;
}

有点小的兴奋,大家U极发言哟!Q!

主要参考:(x) http://blog.csdn.net/jicao/archive/2006/07/01/861343.aspx 
                     http://blog.csdn.net/hjsunj/archive/2008/01/07/2028597.aspx
                     《c++设计新思维?/p>

]]>
C语言怎么解析声明 熟练c/c++(?http://www.shnenglu.com/iuranus/archive/2009/01/08/71530.html攀?/dc:creator>攀?/author>Thu, 08 Jan 2009 13:09:00 GMThttp://www.shnenglu.com/iuranus/archive/2009/01/08/71530.htmlhttp://www.shnenglu.com/iuranus/comments/71530.htmlhttp://www.shnenglu.com/iuranus/archive/2009/01/08/71530.html#Feedback0http://www.shnenglu.com/iuranus/comments/commentRss/71530.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/71530.html         首先声明如果?/span>?/span>int (*a)[10], char* const (*next());?/span>l了解,׃要看了,一个声明是没什么意思的Q这文章只是想阐述?/span>C语言是怎么解析它的声明?/span>     

         声明里面可以包括的元素有Q?/span>cd说明W?/span>(int, void, char,struct...)Q存储类?/span>extern, static, register, cd限定W?/span>(const, volatile), 变量?/span>(标识W?/span>), W号(*Q?/span>圆括号和中括?/span>)Q?/span>

       M原则是,扑ֈ标识W?/span>(x?/span>们^时叫的变量名)Q从叛_左解析;

       具体?/span>骤如下:(x)

       1. 扑ֈ声明中最?/span>边的标识W?/span>,L标识W?/span>   => 变量是叫标识W?/span>

       2. 查看标识W右边的下一个符?/span>Q?/span>如果是方括号Q取出可能的大小Q去掉方括号 Q?/span>>是一个数l?/span>?/span>

    3. 查看标识W右边的下一个符?/span>Q?/span>

 如果是左圆括P取出可能的参敎ͼ一直到x?/span> Q?/span>> 是一个函?/span>

       4. 查看标识W左边的W号Q?/span>如果是左括号Q找?/span>对应的右括号Qƈ把括号中的声明组合在一?/span>。回到第2步重新开始执行?/span>

       5. 查看标识W左边的W号Q?/span>如果?/span>const, volatile,*, l箋向左ȝC是这三个cd为止?/span>重复W?span>4步? =>?/span>释ؓ(f)const, volatile,指向什么的指针

       6. 剩下的符号一q?/span>d =>static unsigned int

       你可能想问这几步可以解决了? 是的Q这是所谓的奇解码环?/span>

    下面我来随便验证下这个算?span>:

       先来个简单的

int (*a)[10] ?int* a[10];

   声明?span>       步骤               执行l果

int (*a)[10]    W?span>1?nbsp;          扑ֈ最左边的标识符aQ表C?span>a是一?span>…

int (*)[10]      W?span>2Q?span>3?span>    不匹?/span>

int (*)[10]      W?span>4?span>          匚w(,直接d),包括*Q表C?span>a是一个指?span>…指针.Step2

int [10]          W?span>2?span>           匚w[10]Q表C?span>a是一个指?span>..size=10的数l的指针

int                 W?span>3Q?span>4Q?span>5    不匹?/span>

l束            W?span>6?span>           表示a是一个指?span>int数组的指?/span>

int* a[10]     W?span>1?span>           a是一?/span>

int* [10]       W?span>2?span>           a是一?span>…size=10的数l?/span>

int*              W?span>3?span>           不匹?/span>

int                W?span>4?span>           匚wQ?span>a是一个存攄指针Q?span>size=10的数l?/span>

int                W?span>5?span>           匚wQ?span>a是一个存攄int指针Q?span>size=10的数l?/span>

       大家?/span>的出两个声明的结果是一个是指针Q一个是数组?/span>

    int a1[10];

    int a2[20];

    int (*b)[10];

    int* c[10];

    a[0] = 10;

    b = &a2;    //报错Q?/span>cannot convert from 'int (*)[20]' to 'int (*)[10]'

    b = &a1;    //b是指?/span>size=10的数l的指针

    c[0] = &a1[0]; //c是一个数l,里面存放的是指针Q指针指?/span>int;


Q未完待l)

]]>
l构体对齐那点事 熟练c/c++(? http://www.shnenglu.com/iuranus/archive/2009/01/06/71388.html攀?/dc:creator>攀?/author>Tue, 06 Jan 2009 15:39:00 GMThttp://www.shnenglu.com/iuranus/archive/2009/01/06/71388.htmlhttp://www.shnenglu.com/iuranus/comments/71388.htmlhttp://www.shnenglu.com/iuranus/archive/2009/01/06/71388.html#Feedback9http://www.shnenglu.com/iuranus/comments/commentRss/71388.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/71388.html          刚刚完成一个文件的q移E序Q其中遇Cl构体对齐的问题Q所以拿出来说说Q与各位博友们分享?/span>

我的E序很简单,是把之前通过一个结构体fwrite到文?/span>A里的内容dQ然后{l另一个结构体保存。程序是单,但我担心的是之前?/strong>l构?/span>fwrite到文?/span>A的程序对齐结构体规则是怎样的?一定要知道它吗? 当然了,如果那个E序l构体是按照1寚w写入的,我的E序l构体是按照4寚wdQ那不就p了Q?/span>

      q里我引入结构体寚w的概念,也可以说是内存对齐了。ؓ(f)什么要内存寚w呢,是方便CPUd了,具体原因大家要参考计机体系l构了。先看一个内存对齐的例子Q?/span>

      struct example1{

           char a;

           double b;

           long l;

};

      struct example2{

           char a;

           long l;

           double b;

};

大家算l构体大,初次接触的博友可能对{案有点惊讶Q?/span>VC~译Q?/span> sizeof后结果分别是Q?/span>24Q?/span>16?/span> 同样是的l构体,成员换了序Q大就不同了。其实内存对齐有个规则,只要知道了,?/span>OK。那么以?/span>5Ҏ(gu)关键

1Q?span>          内存寚w与编译器讄有关Q首先要搞清~译器这个默认值是多少

2Q?span>          如果不想~译器默认的话,可以通过#pragma pack(n)来指定按?/span>n寚w

3Q?span>          每个l构体变量对齐,如果寚w参数n(~译器默认或者通过pragma指定)大于该变量所占字节数(m)Q那么就按照m寚wQ内存偏Ud的地址?/span>m的倍数Q否则是按照n寚wQ内存偏Ud的地址?/span>n的倍数。也是最化长度规则

4Q?span>          l构体d?/span>: 寚w后的长度必须是成员中最大的寚w参数的整数倍。最大对齐参数是从第三步得到的?/span>

5Q?span>          补充Q如果结构体A中还要结构体BQ那?/span>B的对齐方式是选它里面最长的成员的对齐方?/span>

所以计结构体大小要走三步Q首先确定是当前E序按照几对?/span>(参照1Q?/span>2?/span>)Q接着计算每个l构体变量的大小和偏U?/span>(参照3Q?/span>5)Q最后计结构体d(参照4Q?/span>

      先算?/span>example1吧,假设~译器是?/span>16寚w?/span>

      1Q确定按照几寚w: 16;

      2Q确定每个成员的偏移Q?/span>a 占一个字节,16>1, 按照1寚wQv始位|?/span>0Q?/span>0%1 = 0Q那?/span>a存?/span>0位置Q?/span>b?/span>8个字节,16>8Q按?/span>8寚wQv始位|就不能?/span>1了,因ؓ(f)要按?/span>8寚wQ所以最q的偏移起始位置?/span>8Q?/span> 8%8 =0, 那么b存在位|?/span>8-15的位|;l?/span>4个字节,16>4Q按?/span>4寚wQv始位|?/span>16Q?/span> 16%4=0Q那?/span>l存在位|?/span>16-19的位|。所以结构体?/span>0?/span>19一共占?/span>20个字?/span>

      3Q结构体d:(x)成员中最大的寚w参数?/span>b?/span>8寚wQ所?/span>20Q?/span>8!=0, 24刚好?/span>

      真的很搞Q同理计?/span>example2应该?/span>16Q?/span>

     再D个结构体嵌套的例子吧Q?/span>

#pragma pack(push)

#pragma pack(8)

struct test1{

      int a;

      char b;

      int c[20]

long l;

} ;

struct test2{

      char a1;

      char a2;

      struct test1 t1;

      double b1;

}

#pragma pack(pop)

先计?/span>test1, 8寚wQ?/span>a占用0-3Q?/span>b占用4Q?/span>c占用8Q?/span>87Q?/span>l占用88Q?/span>91Q一?/span>92个字节。成员中最大的寚w参数?/span>int?/span>92%4=0;

再计?/span>test2, a1z占用0Q?/span>a2占用1Q?/span>t1呢,4 % 4 (test1里面最长的成员的对齐方? = 0, 4-95Q?/span>b1?/span>96?/span>103Q一?/span>104个字节,成员中最大的寚w参数?/span>double?/span>104%8=0; 所以是104.


      那关于我文章开头提到的那个文g转换Q我现在只要知道原始E序是按照什么对齐的Q然后在新程序中指定按照几对齐就可以了,哈哈Q?nbsp;           
      
      挤时间写的,
有的地方有遗漏,请各位指正!



]]>
publicl承后,父类与子c访问隐?熟练c/c++(?http://www.shnenglu.com/iuranus/archive/2009/01/05/71210.html攀?/dc:creator>攀?/author>Mon, 05 Jan 2009 03:16:00 GMThttp://www.shnenglu.com/iuranus/archive/2009/01/05/71210.htmlhttp://www.shnenglu.com/iuranus/comments/71210.htmlhttp://www.shnenglu.com/iuranus/archive/2009/01/05/71210.html#Feedback0http://www.shnenglu.com/iuranus/comments/commentRss/71210.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/71210.html         《Effective C++》的W六章节l承与面向对象设计花了大部分的篇q在介绍l承遮掩(Hiding Inherited Name)Q那我也效仿下大师,做个的ȝ?br>         publicl承的目的是要徏立父子类的is-a关系Q也是说用到父cȝ地方Q在子类一定能用。现实的代码~写中,我们主要也是用publicl承Q所以每个h都有自己一套承的写法和调用,直到看到Effecitve C++Ӟ才会(x)发现q有很多其它的用法,在这里我q不鼓励大家试各种写法Q毕竟代码要E_Q我只是x一些可能的形式表现出来Q供大家参考?br>class Base
{
 public:
       virtual void fn() = 0;
       virtual void fn(int i){printf("\n Base: fn(int)\n");};
       virtual void fn2() {printf("\n Base: void fn2(int)\n");}
       void fn3() {printf("\n Base: fn3()\n");}
       void fn4(){printf("\n Base: fn4()\n");}
};

class ClassA : public Base
{
public:
      ClassA(int n, int d);
      // using Base::fn2;
      virtual void fn(){printf("\n ClassA: fn()\n");};
       virtual void fn(int i){printf("\n ClassA: fn(INT)\n");};

       virtual void fn2(int i) {printf("\n ClassA: fn2(INT)\n"); }

       void fn3() {printf("\n ClassA: fn3()\n");}
       void fn4(int i){printf("\n ClassA: fn4()\n");}
 };
int main()

Base* pBase1 = new ClassA(10, 20);
 pBase1->fn();              //OKQClassA: fn()
 pBase1->fn(11);          //OKQClassA: fn(INT)
 pBase1->fn2();            //OKQBase: void fn2(int)
 pBase1->fn2(2);          //NO, 不能讉K
 pBase1->fn3();            //OKQBase: fn3()
 pBase1->fn4();            //OKQBase: fn4()
 pBase1->fn4(2);          //NOQ不能访?br> printf("\n============================================\n");
 ClassA* pDerived = new ClassA(10, 20);
 pDerived->fn();            //OKQClassA: fn()
 pDerived->fn(1);          //OKQClassA: fn(INT)
 pDerived->fn2();          //NOQ不能访?br> pDerived->fn2(2);        //OKQClassA: fn2(INT)
 pDerived->fn3();          //OKQClassA: fn3()
 pDerived->fn4();          //NOQ不能访?br> pDerived->fn4(2);        //NOQClassA: fn4(INT)
 printf("\n============================================\n");
 return 0;      
}


子类父类同名virtual函数(参数相同)Q?用子cȝ指针Q引用,对象讉KӞ子类?x)覆盖父cL?只能讉K子类Ҏ(gu))?br>子类父类同名virtual函数(参数相同)Q?用父cȝ指针Q引用,对象讉KӞ子类?x)覆盖父cL?只能讉K子类Ҏ(gu))?br>子类父类同名virtual函数(参数不同)Q?用子cȝ指针Q引用,对象讉KӞ子类?x)覆盖父cL?只能讉K子类Ҏ(gu))?br>子类父类同名virtual函数(参数不同)Q?用父cȝ指针Q引用,对象讉KӞ父类?x)覆盖子cL?只能讉K父类Ҏ(gu))?br>子类父类同名virtual函数(函数cd不同const/non-const)Q?用子cȝ指针Q引用,对象讉KӞ子类?x)覆盖父cL?只能讉K子类Ҏ(gu))?br>子类父类同名virtual函数(函数cd不同const/non-const)Q?用父cȝ指针Q引用,对象讉KӞ父类?x)覆盖子cL?只能讉K父类Ҏ(gu))?/p>

l论Q参数和函数cd是c++~译器判断要不要多态的关键因素。注: q回cd不同Ӟ~译器会(x)报错Qvirtual不能和staticq用。静态成员函敎ͼ没有隐藏的this指针Qvirtual函数一定要通过对象来调用,既要this指针?br>改进:Q如果子cL针想讉K到父c,可以在子c里加入:using 父类?:函数名;如pDerived->fn2(); 讉K父类Ҏ(gu)Q在ClassA里面加入using Base::fn2Q就可以讉K了。如果父cL针想讉K到子c,需要指针{换了?br>
子类父类同名non-virtual函数(无论参数/q回/函数cd(const或static))Q用子类的指针,引用Q对象访问,子类?x)覆盖父cL?只能讉K子类Ҏ(gu))?br>子类父类同名non-virtual函数(无论参数/q回/函数cd(const或static))Q用父类的指针,引用Q对象访问,父类?x)覆盖子cL?只能讉K父类Ҏ(gu))?br>
l论: non-virtual函数Q既没有M多态效果,如果父类要访问子c,只用指针转换?nbsp;  

         所谓大道至Q想必大家看着q个都烦Q我也是。想了想应该q样表达最单:(x)
 
         子类publicl承父类的函敎ͼ唯有满(参数Q返回|函数cd相同&父类是virtual)函数Q父cȝ指针Q引?也指针实现的)能够多态的讉K子类Q否则父cL针只能访问父cȝҎ(gu)?nbsp;
         
         子类publicl承父类的函敎ͼ子类的方法名?x)遮掩父cȝ相同名的Ҏ(gu)。子c要惌问父cȝҎ(gu)Q用using 父类?:函数名?nbsp;   
       
         具体的原因我觉得可能q是得找旉拜读下候杰译的《C++对象模型》,看看到底q个东西是怎么设计的?br>



]]>
Q{载)图文例解C++cȝ多重l承与虚拟?/title><link>http://www.shnenglu.com/iuranus/archive/2008/12/18/69722.html</link><dc:creator>攀?/dc:creator><author>攀?/author><pubDate>Thu, 18 Dec 2008 03:15:00 GMT</pubDate><guid>http://www.shnenglu.com/iuranus/archive/2008/12/18/69722.html</guid><wfw:comment>http://www.shnenglu.com/iuranus/comments/69722.html</wfw:comment><comments>http://www.shnenglu.com/iuranus/archive/2008/12/18/69722.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/iuranus/comments/commentRss/69722.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/iuranus/services/trackbacks/69722.html</trackback:ping><description><![CDATA[在过ȝ学习(fn)中,我们始终接触的单个类的承,但是在现实生zMQ一些新事物往往?x)拥有两个或者两个以上事物的属性,Z解决q个问题QC++引入了多重承的概念Q?font color=#ff0000><strong>C++允许Z个派生类指定多个基类Q这L(fng)l承l构被称做多重?/strong></font>? <p>  举个例子Q交通工L(fng)可以z出汽车和船两个子c,但拥有汽车和船共同特性水陆两用汽车就必须l承来自汽RcM船类的共同属性?<br><br>  由此我们不难惛_如下的图例与代码Q?/p> <p align=center><img alt="" src="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/pic/21cppc01.gif" border=0></p> <p> <font style="BACKGROUND-COLOR: #b000b0" color=#ffffff>当一个派生类要用多重承的时候,必须在派生类名和冒号之后列出所有基cȝcdQƈ用逗好分隔?/font> </p> <p class=code clear=both><font color=green>  </font> <br>  <br>#include <<font color=maroon>iostream</font>>  <br><font color=blue>using</font> <font color=blue>namespace</font> std;  <br>  <br><font color=blue>class</font> Vehicle  <br>{  <br>    <font color=blue>public</font>:  <br>        Vehicle(<font color=blue>int</font> weight <font color=red>=</font> 0)  <br>        {  <br>            Vehicle::weight <font color=red>=</font> weight;  <br>        }  <br>        <font color=blue>void</font> SetWeight(<font color=blue>int</font> weight)  <br>        {  <br>            <font color=maroon>cout</font><<"重新讄重量"<<endl;  <br>            Vehicle::weight <font color=red>=</font> weight;  <br>        }  <br>        <font color=blue>virtual</font> <font color=blue>void</font> ShowMe() <font color=red>=</font> 0;  <br>    <font color=blue>protected</font>:  <br>        <font color=blue>int</font> weight;  <br>};  <br><font color=blue>class</font> Car:<font color=blue>public</font> Vehicle<font color=green>//汽R </font> <br>{  <br>    <font color=blue>public</font>:  <br>        Car(<font color=blue>int</font> weight=0,<font color=blue>int</font> aird=0):Vehicle(weight)  <br>        {  <br>            Car::aird <font color=red>=</font> aird;  <br>        }  <br>        <font color=blue>void</font> ShowMe()  <br>        {  <br>            <font color=maroon>cout</font><<"我是汽RQ?<<endl;  <br>        }  <br>    <font color=blue>protected</font>:  <br>        <font color=blue>int</font> aird;  <br>};  <br>  <br><font color=blue>class</font> Boat:<font color=blue>public</font> Vehicle<font color=green>//?nbsp;</font> <br>{  <br>    <font color=blue>public</font>:  <br>        Boat(<font color=blue>int</font> weight=0,<font color=blue>float</font> tonnage=0):Vehicle(weight)  <br>        {  <br>            Boat::tonnage <font color=red>=</font> tonnage;  <br>        }  <br>        <font color=blue>void</font> ShowMe()  <br>        {  <br>            <font color=maroon>cout</font><<"我是船!"<<endl;  <br>        }  <br>    <font color=blue>protected</font>:  <br>        <font color=blue>float</font> tonnage;  <br>};  <br>  <br><font color=blue>class</font> AmphibianCar:<font color=blue>public</font> Car,<font color=blue>public</font> Boat<font color=green>//水陆两用汽R,多重l承的体?nbsp;</font> <br>{  <br>    <font color=blue>public</font>:  <br>        AmphibianCar(<font color=blue>int</font> weight,<font color=blue>int</font> aird,<font color=blue>float</font> tonnage)  <br>        :Vehicle(weight),Car(weight,aird),Boat(weight,tonnage)  <br>        <font color=green>//多重l承要注意调用基cL造函?nbsp;</font> <br>        {  <br>          <br>        }  <br>        <font color=blue>void</font> ShowMe()  <br>        {  <br>            <font color=maroon>cout</font><<"我是水陆两用汽RQ?<<endl;  <br>        }  <br>};  <br><font color=blue>int</font> <font color=blue>main</font>()  <br>{  <br>    AmphibianCar a(4,200,1.35f);<font color=green>//错误 </font> <br>    a.SetWeight(3);<font color=green>//错误 </font> <br>    system("pause");   <br>}</p> <p>  上面的代码从表面看,看不出有明显的语发错误,但是它是不能够通过~译的。这有是Z么呢Q?<br>  q是׃多重l承带来?font color=#ff0000><font color=#ff0000>l承的模p?/font></font>带来的问题?/p> <p>  先看如下的图C:(x) </p> <p> </p> <p align=center><img alt="" src="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/pic/21cppc02.gif" border=0></p> <p>  在图中深U色标记出来的地Ҏ(gu)是主要问题所在,水陆两用汽Rcȝ承了来自CarcMBoatcȝ属性与Ҏ(gu)QCarcMBoatcd为AmphibianCarcȝ基类Q在内存分配上AmphibianCar获得了来自两个类的SetWeight()成员函数Q当我们调用a.SetWeight(3)的时候计机不知道如何选择分别属于两个基类的被重复拥有了的cL员函数SetWeight()?</p> <p>  ׃q种模糊问题的存在同样也D了AmphibianCar a(4,200,1.35f);执行p|Q系l会(x)产生Vehicle”不是基或成员的错误?/p> <p>  以上面的代码ZQ我们要惌AmphibianCarcL获得一个Vehicle的拷贝,而且又同时共享用CarcMBoatcȝ数据成员与成员函数就必须通过C++所提供?font color=#ff0000><strong>虚拟l承</strong></font>技术来实现?/p> <p>  我们在CarcdBoatcȝ承VehiclecdQ在前面加上virtual关键字就可以实现虚拟l承Q用虚拟承后Q?font style="BACKGROUND-COLOR: #b000b0" color=#ffffff>当系l碰到多重承的时候就?x)自动先加入一个Vehicle的拷贝,当再ơ请求一个Vehicle的拷贝的时候就?x)被忽略Q保证承类成员函数的唯一?/font>?<br><br>  修改后的代码如下Q注意观察变化:(x)</p> <p class=code><br>#include <<font color=maroon>iostream</font>>  <br><font color=blue>using</font> <font color=blue>namespace</font> std;  <br>  <br><font color=blue>class</font> Vehicle  <br>{  <br>    <font color=blue>public</font>:  <br>        Vehicle(<font color=blue>int</font> weight <font color=red>=</font> 0)  <br>        {  <br>            Vehicle::weight <font color=red>=</font> weight;  <br>            <font color=maroon>cout</font><<"载入VehiclecL造函?<<endl;  <br>        }  <br>        <font color=blue>void</font> SetWeight(<font color=blue>int</font> weight)  <br>        {  <br>            <font color=maroon>cout</font><<"重新讄重量"<<endl;  <br>            Vehicle::weight <font color=red>=</font> weight;  <br>        }  <br>        <font color=blue>virtual</font> <font color=blue>void</font> ShowMe() <font color=red>=</font> 0;  <br>    <font color=blue>protected</font>:  <br>        <font color=blue>int</font> weight;  <br>};  <br><font color=blue>class</font> Car:<font color=blue>virtual</font> <font color=blue>public</font> Vehicle<font color=green>//汽RQ这里是虚拟l承 </font> <br>{  <br>    <font color=blue>public</font>:  <br>        Car(<font color=blue>int</font> weight=0,<font color=blue>int</font> aird=0):Vehicle(weight)  <br>        {  <br>            Car::aird <font color=red>=</font> aird;  <br>            <font color=maroon>cout</font><<"载入CarcL造函?<<endl;  <br>        }  <br>        <font color=blue>void</font> ShowMe()  <br>        {  <br>            <font color=maroon>cout</font><<"我是汽RQ?<<endl;  <br>        }  <br>    <font color=blue>protected</font>:  <br>        <font color=blue>int</font> aird;  <br>};  <br>  <br><font color=blue>class</font> Boat:<font color=blue>virtual</font> <font color=blue>public</font> Vehicle<font color=green>//?q里是虚拟?nbsp;</font> <br>{  <br>    <font color=blue>public</font>:  <br>        Boat(<font color=blue>int</font> weight=0,<font color=blue>float</font> tonnage=0):Vehicle(weight)  <br>        {  <br>            Boat::tonnage <font color=red>=</font> tonnage;  <br>            <font color=maroon>cout</font><<"载入BoatcL造函?<<endl;  <br>        }  <br>        <font color=blue>void</font> ShowMe()  <br>        {  <br>            <font color=maroon>cout</font><<"我是船!"<<endl;  <br>        }  <br>    <font color=blue>protected</font>:  <br>        <font color=blue>float</font> tonnage;  <br>};  <br>  <br><font color=blue>class</font> AmphibianCar:<font color=blue>public</font> Car,<font color=blue>public</font> Boat<font color=green>//水陆两用汽R,多重l承的体?nbsp;</font> <br>{  <br>    <font color=blue>public</font>:  <br>        AmphibianCar(<font color=blue>int</font> weight,<font color=blue>int</font> aird,<font color=blue>float</font> tonnage)  <br>        :Vehicle(weight),Car(weight,aird),Boat(weight,tonnage)  <br>        <font color=green>//多重l承要注意调用基cL造函?nbsp;</font> <br>        {  <br>            <font color=maroon>cout</font><<"载入AmphibianCarcL造函?<<endl;  <br>        }  <br>        <font color=blue>void</font> ShowMe()  <br>        {  <br>            <font color=maroon>cout</font><<"我是水陆两用汽RQ?<<endl;  <br>        }  <br>        <font color=blue>void</font> ShowMembers()  <br>        {  <br>            <font color=maroon>cout</font><<"重量Q?<<weight<<","<<"I气排量Q?<<aird<<"CCQ?<<"排水量:(x)"<<tonnage<<"?<<endl;  <br>        }  <br>};  <br><font color=blue>int</font> <font color=blue>main</font>()  <br>{  <br>    AmphibianCar a(4,200,1.35f);  <br>    a.ShowMe();  <br>    a.ShowMembers();  <br>    a.SetWeight(3);  <br>    a.ShowMembers();  <br>    system("pause");   <br>}</p> <p>  注意观察cL造函数的构造顺序?<br><br><strong>  虽然说虚拟承与虚函数有一定相似的地方Q但读者务必要CQ他们之间是l对没有M联系的!</strong></p> <img src ="http://www.shnenglu.com/iuranus/aggbug/69722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/iuranus/" target="_blank">攀?/a> 2008-12-18 11:15 <a href="http://www.shnenglu.com/iuranus/archive/2008/12/18/69722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++怎么实现AOPhttp://www.shnenglu.com/iuranus/archive/2007/12/14/38507.html攀?/dc:creator>攀?/author>Fri, 14 Dec 2007 06:02:00 GMThttp://www.shnenglu.com/iuranus/archive/2007/12/14/38507.htmlhttp://www.shnenglu.com/iuranus/comments/38507.htmlhttp://www.shnenglu.com/iuranus/archive/2007/12/14/38507.html#Feedback5http://www.shnenglu.com/iuranus/comments/commentRss/38507.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/38507.html            AOP技术的诞生q不晚Q早?990q开始,来自Xerox Palo Alto Research LabQ即PARCQ的研究人员对面向对象思想的局限性进行了分析。他们研I出了一U新的编E思想Q借助q一思想或许可以通过减少代码重复模块从而帮助开发h员提高工作效率。随着研究的逐渐深入QAOP也逐渐发展成一套完整的E序设计思想Q各U应用AOP的技术也应运而生?/p>

            AOP技术在Javaq_下是最先得到应用的。就在PARC对于面向斚w~程q行研究的同Ӟ国Northeastern University的博士生Cristina Lopes和其同事也开始了cM的思考。最l,国国防先进技术研I计划vQDefense Advanced Research Projects Agency即DARPAQ注意到了这工作,q提供了U研l费Q鼓励将二者的工作成果l合h。他们通过定义一套Java语言的扩展系l,使开发者可以方便的q行面向斚w的开发,q套扩展pȝ被称为AspectJ。之后,AspectJ?002q被转让lEclipse FoundationQ从而成为在开源社ZAOP技术的先锋Q也是目前最为流行的AOP工具?br>
            那么对于C++技术来_(d)怎样来开展AOP呢,q好有Olaf Spinczyk q样的h存在Q我们也有了aspect c++。它使用了插入代码的Ҏ(gu)。一个典型的Aspect C++CZ需要一个C++源文?.cpp)、一个aspect C++源文?.ah)Q通过ac++~译器把C++源文件和aspect C++源文件{换成混合的C++源文?如果有头文g也会(x)转换)Q最后通过普通的C++~译器编译出可执行文件?br> 
            那么我现在如果不想用W三方编译器Q自己去实现AOPQ不知道CPPBLOG里的大虾有什么想法?



]]>
谈const 熟练C/C++Q二Q?/title><link>http://www.shnenglu.com/iuranus/archive/2007/10/11/33967.html</link><dc:creator>攀?/dc:creator><author>攀?/author><pubDate>Thu, 11 Oct 2007 13:09:00 GMT</pubDate><guid>http://www.shnenglu.com/iuranus/archive/2007/10/11/33967.html</guid><wfw:comment>http://www.shnenglu.com/iuranus/comments/33967.html</wfw:comment><comments>http://www.shnenglu.com/iuranus/archive/2007/10/11/33967.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.shnenglu.com/iuranus/comments/commentRss/33967.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/iuranus/services/trackbacks/33967.html</trackback:ping><description><![CDATA[     摘要: const关键字可以说是用途广泛,从对变量的限定到对函数的限定Q尤其是那个指向帔R的指针(const int *pQ,指针帔R(int * const p)Q指向常量的指针帔R(const int* const p)更让初学者摸不到头脑。这里我主要xqC最q项目中关于const的一个问题。其实有的时候还不能被表面现象迷惑了Q简单代码如?nbsp; <a href='http://www.shnenglu.com/iuranus/archive/2007/10/11/33967.html'>阅读全文</a><img src ="http://www.shnenglu.com/iuranus/aggbug/33967.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/iuranus/" target="_blank">攀?/a> 2007-10-11 21:09 <a href="http://www.shnenglu.com/iuranus/archive/2007/10/11/33967.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>q回内部静态成? 熟练C/C++Q一Q? http://www.shnenglu.com/iuranus/archive/2007/04/13/21798.html攀?/dc:creator>攀?/author>Fri, 13 Apr 2007 08:07:00 GMThttp://www.shnenglu.com/iuranus/archive/2007/04/13/21798.htmlhttp://www.shnenglu.com/iuranus/comments/21798.htmlhttp://www.shnenglu.com/iuranus/archive/2007/04/13/21798.html#Feedback1http://www.shnenglu.com/iuranus/comments/commentRss/21798.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/21798.html        看完陈皓?/span>C/C++q回内部静态成员的陷阱Q认识到自己实?/span>C/C++本n语法研究的不够清楚,所以这些时间就在对基本知识q行回顾Q真的还蛮有意思的?/span>

        我在?/span>C/C++函数Ӟ从没有全面考虑q该函数功能Q只是知道它能做Q基本对函数l节没有了解Q就拿下面这个函数做个例子:(x)

        char *inet_ntoa(struct in_addr in);

        struct in_addr {      unsigned long int s_addr; }

 

        看到q个我就能想到该函数是把一?/span>unsigned long type的数转换成一个字W串。其它什么都不想。现在让我们来仔l品读里面的东西?/span>

        我传入一?/span>unsigned long type的数据,它给我传Z?/span>char *Q那q个char * 在函数里怎么分配I间的。首先不可能是堆分配Q因为如果是那样的话Q你用完q个函数后还要释放资源。其ơ不可能是栈分配Q因为那样函数返回后栈也?x)跟着释放。那q有可能是全局变量Q如果这L(fng)话,C/C++中已l有好多全局了。那q有一U是static的可能,static不会(x)随着函数的返回而释放,也就是说Q它是一块长期被分配的内存空_(d)现在在假若我在程序中q样写:(x)

        printf(“%s, %s”, inet_ntoa(a), inet_ntoa(b)); //a, b 是两个不相等的?/span>

        输出?x)让我大吃一惊,输出l果一栗原因很单,是printf先求bQ把值给了那?/span>staticQ然后再?/span>a, 把值又l了staticQ?/span>static的那块内存最l被写入?/span>a的|q个时候输出,那当然就输出的同一个g。还有一U错误写法,如下Q?/span>

 

        Char *tmp1 = inet_ntoa(a);

        Char *tmp2 = inet_ntoa(b);

        q样也是有问题的Q因?/span>tmp1?/span>tmp2都指向了一块内存,当前?/span>static的值就?/span>b的g。所以ȝ如下Q用这U函C定要copy函数q回的|而不能去保存其内存地址Q?br>附inet_ntoa()源码Q?br>#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <bits/libc-lock.h>

/* The interface of this function is completely stupid, it requires a
   static buffer.  We relax this a bit in that we allow at least one
   buffer for each thread.  */


/* This is the key for the thread specific memory.  */
static __libc_key_t key;

/* If nonzero the key allocation failed and we should better use a
   static buffer than fail.  */

static char local_buf[18];
static char *static_buf;                                //静?/span>

/* Destructor for the thread-specific data.  */
static void init (void);
static void free_key_mem (void *mem);


char *
inet_ntoa (struct in_addr in)
{
  __libc_once_define (static, once);
  char *buffer;
  unsigned char *bytes;

  /* If we have not yet initialized the buffer do it now.  */
  __libc_once (once, init);

  if (static_buf != NULL)
    buffer = static_buf;
  else
    {
      /* We don't use the static buffer and so we have a key.  Use it
to get the thread-specific buffer.  */

      buffer = __libc_getspecific (key);
      if (buffer == NULL)
{
  /* No buffer allocated so far.  */
  buffer = malloc (18);
  if (buffer == NULL)
    /* No more memory available.  We use the static buffer.  */
    buffer = local_buf;
  else
    __libc_setspecific (key, buffer);
}
    }

  bytes = (unsigned char *) &in;
  __snprintf (buffer, 18, "%d.%d.%d.%d",
      bytes[0], bytes[1], bytes[2], bytes[3]);

  return buffer;
}


/* Initialize buffer.  */
static void
init (void)
{
  if (__libc_key_create (&key, free_key_mem))
    /* Creating the key failed.  This means something really went
       wrong.  In any case use a static buffer which is better than
       nothing.  */

    static_buf = local_buf;
}



]]>
心情不错http://www.shnenglu.com/iuranus/archive/2007/03/28/20799.html攀?/dc:creator>攀?/author>Wed, 28 Mar 2007 11:52:00 GMThttp://www.shnenglu.com/iuranus/archive/2007/03/28/20799.htmlhttp://www.shnenglu.com/iuranus/comments/20799.htmlhttp://www.shnenglu.com/iuranus/archive/2007/03/28/20799.html#Feedback4http://www.shnenglu.com/iuranus/comments/commentRss/20799.htmlhttp://www.shnenglu.com/iuranus/services/trackbacks/20799.htmll过一些时候项目中?/span> C++ 的用,我算是有一?/span> C++ 的项目经验,但是反过来说Q我只是写些基本的程序,没有深入到构Ӟ主要q是?/span> C 的思想Q昨天写 struct Ӟ我发现在 C ?/span> C++ 中写法是不是L(fng)?/span>

C Q?/span>

  struct Node{              // 声明

       int node;

       struct Node *next;        // 定义

  };

  struct Node list;

  或?/span>

  typedef  Node {         

   int node;

   struct Node *next;

}ListLink;

  ListLink list;

 

C++:

  struct Node{

    Int node;

    Node *next;

};

Node list;               // 搞定?/span>

q样一?/span> C++ 的确实在代码的层面上单了Q但理解h却不是很舒服Q?/span>

今天刚接CQ务做 Wireless-Lan Q好长时间没做正事了Q这两天主要在写文档Q东西还比较多,但是和我一l的 Danel人很?/span> Q给我讲了下整个 class diagram 的流E,虽没?/span> sequence 那么Ҏ(gu)理解Q但我还是懂了。而且我发C写程序时特别开心,心态很好,q也是我在追求的Q慢慢来吧。ȝ说这周五之前做出点东西,呵呵Q不能让他失望呀Q过?x)再看看代码Q?/span> GUI Q我蛮喜Ƣ写的?/span>

再说说今天用的那个工P SOURCE INSIGHT Q真爽。看代码的强有力工具。下ơ给 PASSION 的兄弟们介绍下?/span>



]]>
C的基本实?/title><link>http://www.shnenglu.com/iuranus/archive/2006/12/31/17092.html</link><dc:creator>攀?/dc:creator><author>攀?/author><pubDate>Sun, 31 Dec 2006 08:00:00 GMT</pubDate><guid>http://www.shnenglu.com/iuranus/archive/2006/12/31/17092.html</guid><wfw:comment>http://www.shnenglu.com/iuranus/comments/17092.html</wfw:comment><comments>http://www.shnenglu.com/iuranus/archive/2006/12/31/17092.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/iuranus/comments/commentRss/17092.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/iuranus/services/trackbacks/17092.html</trackback:ping><description><![CDATA[<h3 class=post-title>C的实现都是有两个不同的环境:(x)译与执?br></h3> 译Q?br> <ol> <li>把多个源文g~译成目标代码。编译分为预处理?把类g#define的替换源文g)Q然后解析,也就是来识别代码Q大多数错误和警告生在q步Q最后目标代码便生成。这个过E中也可以加入优化器来优化代码? <li>把目标代码与标准库函数用链接器捆l在一P用于执行?/li> </ol> <p>执行Q?/p> <ol> <li>E序载入内存? <li>E序执行? <li>E序l止?/li> </ol> <img src ="http://www.shnenglu.com/iuranus/aggbug/17092.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/iuranus/" target="_blank">攀?/a> 2006-12-31 16:00 <a href="http://www.shnenglu.com/iuranus/archive/2006/12/31/17092.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.iioki.cn" target="_blank">þۺϾþԾ99ëƬ</a>| <a href="http://www.sbsinc.com.cn" target="_blank">AVһȾþ</a>| <a href="http://www.sijishi.cn" target="_blank">þþƷWWW456C0M</a>| <a href="http://www.hktjj.cn" target="_blank">޷?Vþò</a>| <a href="http://www.theredqp.cn" target="_blank">þþþAVƬ</a>| <a href="http://www.onlymir.cn" target="_blank">þ㽶߿ۿè?v</a>| <a href="http://www.i501.cn" target="_blank">޾þһ</a>| <a href="http://www.elecline.com.cn" target="_blank">þɧ</a>| <a href="http://www.nanling888.cn" target="_blank">þþƷƷ </a>| <a href="http://www.dztsc.cn" target="_blank">þþƷɭ</a>| <a href="http://www.ctcscs.cn" target="_blank">ƷۺϾþ</a>| <a href="http://www.gven.cn" target="_blank">99þ99ֻѷѾƷ</a>| <a href="http://www.mumahack.com.cn" target="_blank">ٸþþþþñŪ߳</a>| <a href="http://www.ndj2.cn" target="_blank">ŷսþþþþþþ</a>| <a href="http://www.qysf88.cn" target="_blank">þþƷһ</a>| <a href="http://www.sansiwu.cn" target="_blank">Ʒ18þþþþvr</a>| <a href="http://www.86mls.cn" target="_blank">ԾþþӰԺ</a>| <a href="http://www.wuhujob.com.cn" target="_blank">þþƷƷ</a>| <a href="http://www.aa110.cn" target="_blank">avԾþþþa鶹 </a>| <a href="http://www.pnpxnc.cn" target="_blank">þèDձɫۺϾþ</a>| <a href="http://www.k5158.cn" target="_blank">һþۺ³³</a>| <a href="http://www.sohucn.com.cn" target="_blank">Բľþþþþ</a>| <a href="http://www.fpzhan.cn" target="_blank">޹Ʒþþ</a>| <a href="http://www.sgcx.net.cn" target="_blank">þþþþ޾ƷӰԺ</a>| <a href="http://www.16pk8.cn" target="_blank">þþƷ˵</a>| <a href="http://www.htlon.cn" target="_blank">ݺɫۺþö </a>| <a href="http://www.cq928.cn" target="_blank">Ʒ99þþþ </a>| <a href="http://www.barf1.com.cn" target="_blank">þ99ھƷ</a>| <a href="http://www.cate365.cn" target="_blank">þþžžþƷ</a>| <a href="http://www.uvmq.cn" target="_blank">99þùѸ</a>| <a href="http://www.zyxslswx.cn" target="_blank">Ʒþ</a>| <a href="http://www.yikafei.cn" target="_blank">97þþþ</a>| <a href="http://www.67335.com.cn" target="_blank">Ʒþþþþ</a>| <a href="http://www.ewoman.com.cn" target="_blank">66þôýվȸ</a>| <a href="http://www.kbsfrp.cn" target="_blank">˾þþAV츾ɫ</a>| <a href="http://www.jkzgjkzl.org.cn" target="_blank">þþþþþþ66ƷƬ</a>| <a href="http://www.dogff.cn" target="_blank">պþëƬ</a>| <a href="http://www.kkfo.cn" target="_blank">Ʒþþþþ</a>| <a href="http://www.ohos33.cn" target="_blank">Ʒþþþ</a>| <a href="http://www.hjj9588.cn" target="_blank">þݺҹҹ2020츾 </a>| <a href="http://www.t2tt.cn" target="_blank">þøŮ߳MBA</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>