Skip navigation.

So Easy[@]Opera

原来如此简单

"#ifdef"在C++中运用

, ,

常常在建立header file的时候需要先写一段文字
比如下面这段话

#ifdef HEADERFILENAME_H
#define HEADERFILENAME_H


class ClassName
{
  ...
};

#endif

那段#ifdef有必要写吗?
其实有些无写都不会影响代码的Runtime
不过对运行速度和文件大小有一定的影响

大概很多人很喜欢用#include来抓取文件吧
炎也很喜欢
总是在main.cpp中include一次
然后又在classfile.cpp中又使用一次
每次都include同样的Headerfile.h
这样就导致了Compiler运作的时候在link的时候会重复同样的headerfile内容
相同重复的内容出现就有可能导致不良的情况的发生
即时没有compilerError或者RunrimeError
也会让程序运行缓慢,想想看吧,在重复compiler一段Code之后产生的程序大小

这里还有更多相关的内容((#if, #ifdef, #ifndef, #else, #elif, #endif, and defined)

uni.cc 免费的二级域名,无广告的哦Image Recover

Comments

Anonymous 24. May 2006, 07:19

wangwang writes:

老大,谢了~~!

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31