c语言转向,从c语言转向c++(Turn from C to c++).doc

从c语言转向c(TurnfromCtoc)

从c语言转向c++(Turn from C to c++)

Chapter 1 turns from C to C++

For everyone, it takes some time to get used to C++, and this process is especially distressing for programmers who are already familiar with C. Since C is a subset of C++, all C technologies can continue to be used, but many are not very useful. For example, C++ programmers think that pointer pointers look strange, and they ask, "why don't you use pointers instead?

C is a simple language. It provides only macros, pointers, structures, arrays, and functions. No matter what the problem is, C is solved by macros, pointers, structures, arrays, and functions. And C++ isn't like that. Acer, pointers, structures, arrays and functions and there are of course, in addition to private and protected members, function overloading and default parameters, constructor and destructor, custom operators, inline functions, references, friends, templates, exceptions, name space, etc.. Using C++ has wider space than using C because there are more options to consider when designing.

In the face of so many choices, many C programmers stick to their old habits. Generally speaking, this is not a big sin. But certain C habits are contrary to the spiritual nature of C++, and they are described in the following terms.

--------------------------------------------------------------------------------

Clause 1: try to use const and inline instead of #define

This clause is best referred to as "try to use the compiler without preprocessing" because #define is often thought to be not part of the language itself. That's one of the problems. Look at the following statement:

#define ASPECT_RATIO 1.653

The compiler will never see the name of the ASPECT_RATIO because it will be removed by the handler before the source gets into the compiler, so ASPECT_RATIO will not be added to the list of symbols. If the code involved in this constant is wrong at compile time, it will be very confusing because the error message refers to 1.653 instead of ASPECT_

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值