读书札记《Thinking in C++》(一)

来源:转载

C和C++定义无参数函数的区别

There is a significant difference between C and C++ for functions with empty argument lists. In C, the declaration:
int func2();
means “a function with any number and type of argument.” This prevents type-checking, so in C++ it means “a function with no arguments.”

在C/C++中void fun(void) 都表示无参数函数

 

标准C++ 头文件引入

As C++ evolved, different compiler vendors chose different extensions for file names. In addition, various operating systems have different restrictions on file names, in particular on name length. These issues caused source code portability problems. To smooth over these rough edges, the standard uses a format that allows file names longer than the notorious eight characters and eliminates the extension. For example, instead of the old style of including iostream.h, which looks like this:
#include <iostream.h>
you can now write:
#include <iostream>

There’s a relationship between namespaces and the way header files are included. Before the current header file inclusion style of <iostream> (that is, no trailing ‘.h’) was standardized, the typical way to include a header file was with the ‘.h’, such as <iostream.h>. At that time, namespaces were not part of the language either. So to provide backward compatibility with existing code, if you say
#include <iostream.h>
it means
#include <iostream>
using namespace std;

 

利用Linker进行函数替换

Because the linker searches files in the order you give them, you can pre-empt the use of a library function by inserting a file with your own function, using the same function name, into the list before the library name appears. Since the linker will resolve any references to this function by using your function before it searches the library, your function is used instead of the library function.

 


分享给朋友:
您可能感兴趣的文章:
随机阅读: