| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6316 人关注过本帖
标题:推荐:C++语言常见问题解答
只看楼主 加入收藏
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
结帖率:100%
收藏
 问题点数:0 回复次数:120 
推荐:C++语言常见问题解答

这些是我在网上看到一些资料,感觉很有用,并把他与大家一起分享。很长,不必所有的都看,选自己比较感觉有兴趣的就好。希望对大家有所帮助。
下面是C++语言常见问答:有兴趣的可以看看,也可以做为查询的依据!
下面的东西都包括在这里:
UyUJGI0C.rar (62.36 KB) 推荐:C++语言常见问题解答




   

[此贴子已经被作者于2006-12-27 21:49:56编辑过]

搜索更多相关主题的帖子: 问题解答 语言 推荐 
2006-12-23 22:28
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

【中译对照表】 
 
      
        abstraction             抽象化. 
        access                  存取. 
        access function         存取函数. 
        alias                   别名. 
        argument                引数. 
        arity                   元数. 
        assignment              设定. 
        associativity           结合律. 
        base class              基底类别. 
        binding                 系结. 
        call                    呼叫. 
        class                   类别、物件类别. 
        composition             成份、零件. 
        constructor             建构子(建构元). 
        container               容器. 
        container class         容器类别. 
        data member             资料成员. 
        declaration             宣告                            <名词>. 
        declare                 宣告                            <动词>. 
        default                 预设、内定. 
        define                  定义                            <动词>. 
        definition              定义                            <名词>. 
        dereference             解参用、解参考. 
        derive                  衍生. 
        destructor              解构子(解构元). 
        dispatch                分派、函数分派. 
        dynamic                 动态. 
        encapsulation           封装、封装性. 
        exception               例外、例外状况(异常). 
        exception handling      例外处理. 
        explicit                明显的、外显的                  <形容词>. 
        expression              运算式. 
        friend                  夥伴. 
        function                函数. 
        genericity              泛型. 
        header file             标头档(引入档、含括档). 
        hide                    遮蔽. 
        hierarchy               阶层. 
        identity                个体识别. 
        implement               实作                            <动词>. 
        implementation          实作                            <名词>. 
        inherit                 继承                            <动词>. 
        inheritance             继承                            <名词>. 
        inline                  行内(列内、内嵌). 
        inspector               查询子. 
        instance                案例、实体(执行个体). 
        instantiate             案例化、实体化                  <动词>. 
        instantiation           案例                            <名词>. 
        keyword                 关键字、保留字. 
        mangle                  签名编码                        <动词>. 
        mangling                签名编码                        <名词>. 
        member                  成员. 
        member function         成员函数. 
        member object           成员物件. 
        method                  运作方法、运算方法. 
        module                  模组. 
        multiple inheritance    多重继承. 
        mutator                 更动子. 
        object                  物件(个体). 
        OO                      物件导向(个体导向). 
        OOP                     物件导向程式设计. 
        operator                运算子. 
        overload                多载(过荷、负载)              <动词>. 
        overloading             多载(过荷、负载)              <名词>. 
        override                覆盖、改写. 
        parameter               参数. 
        persistence             持续性(永续性、持固性)        <名词>. 
        persistent object       持续性物件. 
        pointer                 指标. 
        polymorphism            多型(同名异式). 
        precedence              优先序. 
        pretty printer          美编工具. 
        private                 私有. 
        protected               保护. 
        prototype               原型、函数原型(雏型). 
        public                  公共、公有. 
        pure virtual function   纯虚拟函数. 
        reference               参考、参考值. 
        relation                关系. 
        return value            传回值. 
        semantics               语意. 
        signature               签名、型态签名. 
        smart pointer           聪明的指标. 
        specialization          特异化、特殊化. 
        statement               陈述、指令(指述). 
        static                  静态. 
        structure               结构、记录. 
        subclass                子类别、子代类别. 
        subtype                 子型别、子型态. 
        superclass              父类别、亲代类别. 
        syntax                  语法、文法. 
        template                样版(模版). 
        throw                   丢出. 
        type                    型态、型别. 
        virtual                 虚拟. 
        virtual function        虚拟函数. 

[此贴子已经被作者于2006-12-27 21:51:25编辑过]



ewVGaOpq.rar (62.36 KB)

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:29
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 



为什麽该用 "new" 而不是老字号的 malloc() ? 
 
建构子/解构子、型别安全性、可被覆盖(overridability)。 
 
建构子/解构子:和 "malloc(sizeof(Fred))" 不同,"new Fred()" 还会去呼叫 
Fred 的建构子。同理,"delete p" 会去呼叫 "*p" 的解构子。 
 
型别安全性:malloc() 会传回一个不具型别安全的 "void*",而 "new Fred()" 则 
会传回正确型态的指标(一个 "Fred*")。 
 
可被覆盖:"new" 是个可被物件类别覆盖的运算子,而 "malloc" 不是以「各个类别 
」作为覆盖的基准。 
 

[此贴子已经被作者于2006-12-27 21:52:44编辑过]


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:29
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
为什麽 C++ 不替 "new" 及 "delete" 搭配个 "realloc()" ? 
 
避免你产生意外。 
 
当 realloc() 要拷贝配置区时,它做的是「逐位元 bitwise」的拷贝,这会弄坏大 
部份的 C++ 物件。不过 C++ 的物件应该要能自我拷贝才对:用它们自己的拷贝建构 
子或设定运算子。

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:30
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
我该怎样配置/释放阵列? 
 
用 new[] 和 delete[] : 
 
         Fred* p = new Fred[100]; 
         //... 
         delete [] p; 
 
每当你在 "new" 运算式中用了 "[...]",你就必须在 "delete" 陈述中使用 "[]"。 
                                          ^^^^ 
这语法是必要的,因为「指向单一元素的指标」与「指向一个阵列的指标」在语法上 
并无法区分开来。

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:30
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
万一我忘了将 "[]" 用在 "delete" 由 "new Fred[n]" 配置到的阵列,会发生 
      什麽事? 
 
灾难。 
 
这是程式者的--而不是编译器的--责任,去确保 new[] 与 delete[] 的正确配 
对。若你弄错了,编译器不会产生任何编译期或执行期的错误讯息。堆积(heap)被 
破坏是最可能的结局,或是更糟的,你的程式会当掉。 

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:30
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
成员函数做 "delete this" 的动作是合法的(并且是好的)吗? 
 
只要你小心的话就没事。 
 
我所谓的「小心」是: 
 
   1) 你得 100% 确定 "this" 是由 "new" 配置来的(而非 "new[]",亦非自订的 
      "new" 版本,一定要是最原始的 "new")。 
 
   2) 你得 100% 确定该成员函数是此物件最後一个会呼叫到的。 
 
   3) 做完自杀的动作 ("delete this;") 後,你不能再去碰 "this" 的物件了,包 
      括资料及运作行为在内。 
 
   4) 做完自杀的动作 ("delete this;") 後,你不能再去碰 "this" 指标了。 
      换句话说,你不能查看它、将它与其他指标或是 NULL 相比较、印出其值、 
      对它转型、对它做任何事情。 
 
很自然的,这项警告也适用於:当 "this" 是个指向基底类别的指标,而解构子不是 
virtual 的场合。 
 

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:31
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
我该怎麽用 new 来配置多维阵列? 
 
有很多方法,端视你对阵列大小的伸缩性之要求而定。极端一点的情形,如果你在编 
译期就知道所有阵列的维度,你可以静态地配置(就像 C 一样): 
 
         class Fred { /*...*/ }; 
 
         void manipulateArray() 
         { 
           Fred matrix[10][20]; 
 
           //使用 matrix[i][j]... 
 
           //不须特地去释放该阵列 
         } 
 
另一个极端情况,如果你希望该矩阵的每个小块都能不一样大,你可以在自由记忆体 
里配置之: 
 
         void manipulateArray(unsigned nrows, unsigned ncols[]) 
         //'nrows' 是该阵列之列数。 
         //所以合法的列数为 (0, nrows-1) 开区间。 
         //'ncols[r]' 则是 'r' 列的行数 ('r' 值域为 [0..nrows-1])。 
         { 
           Fred** matrix = new Fred*[nrows]; 
           for (unsigned r = 0; r < nrows; ++r) 
             matrix[r] = new Fred[ ncols[r] ]; 
 
           //使用 matrix[i][j]... 
 
           //释放就是配置的反动作: 
           for (r = nrows; r > 0; --r) 
             delete [] matrix[r-1]; 
           delete [] matrix; 
         } 

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:31
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
C++ 能不能做到在执行时期才指定阵列的长度? 
 
可以。STL 有一个 vector template 提供这种行为。请参考“程式库”一节的 STL 
项目。 
 
不行。内建的阵列型态必须在编译期就指定它的长度了。 
 
可以,内建的阵列可以在执行期才指定第一个索引的□围。譬如说,和上一则 FAQ 
相较,如果你只需要第一个维度大小能够变动,你可以 new 一个阵列的阵列(而不 
是阵列指标的阵列 "an array of pointers to arrays"): 
 
         const unsigned ncols = 100; 
         //'ncols' 不是执行期才决定的变数 (用来代表阵列的行数) 
 
         class Fred { ... }; 
 
         void manipulateArray(unsigned nrows) 
         //'nrows' 是执行期才决定的变数 (用来代表阵列的列数) 
         { 
           Fred (*matrix)[ncols] = new Fred[nrows][ncols]; 
 
           //用 matrix[i][j] 来处理 
 
           //deletion 是物件配置的逆运算: 
           delete [] matrix; 
         } 
 
如果你不光是需要在执行期改变阵列的第一个维度的话,就不能这样做了。

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:32
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
怎样确保某类别的物件都是用 "new" 建立的,而非区域或整体/静态变数? 
 
确定该类别的建构子都是 "private:" 的,并定义个 "friend" 或 "static" 函数, 
来传回一个指向由 "new" 建造出来的物件(把建构子设成 "protected:",如果你想 
要有衍生类别的话)。 
 
         class Fred {    //只允许 Fred 动态地配置出来 
         public: 
           static Fred* create()                 { return new Fred();     } 
           static Fred* create(int i)            { return new Fred(i);    } 
           static Fred* create(const Fred& fred) { return new Fred(fred); } 
         private: 
           Fred(); 
           Fred(int i); 
           Fred(const Fred& fred); 
           virtual ~Fred(); 
         }; 
 
         main() 
         { 
           Fred* p = Fred::create(5); 
           ... 
           delete p; 
         } 

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-12-23 22:33
快速回复:推荐:C++语言常见问题解答
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013698 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved