如何使用编译创建头文件 [英] How to create header file with compiling
问题描述
我还在尝试这样做,但它从未奏效过!
在一个.cpp文件中,我编写了代码,并在开头写道:
#ifndef MYLIST_H
#define MYLIST_H
....结束:
#endif
编译时创建头文件有什么问题?
我是否需要在块中写入#include(s)?
你能告诉我预处理器能做什么和做什么的更多信息吗?
它应该有效,除非...
你包含的某些标题具有相同的MYLIST_H定义。尝试使用更多
随机名称。
#includes可以去任何地方(当然在你使用它们之前)但是
将它们放在#ifndef之后以节省一些加载时间是有意义的(
预处理器会加载文件,每次你的头文件都包含在某处。
-
问候,Ron AF Greve
http://moonlit.xs4all.nl
" Al"< al ******** ****@gmail.com>写在留言中
news:11 ********************** @ g43g2000cwa.googlegr oups .com ...我还在尝试这样做,但它从未奏效过!
在一个.cpp文件中,我编写代码,并在开头写道:
#ifndef MYLIST_H
#define MYLIST_H
...结束:
#endif
创建头文件有什么问题什么时候编译?
我是否需要写入?阻止#include(s)?
你能告诉我预处理器的功能和功能吗?
它可能依赖于编译器吗?我使用Dev-C ++。
Moonlit写道:
它应该有效,除非......
您包含的某些标题具有相同的MYLIST_H定义。尝试采用更随机的名称。
#includes可以去任何地方(当然在你使用它们之前)但是
将它们放在#ifndef之后是有意义的节省一些加载时间(
预处理器会加载文件,每次你的头文件包含在某处。
< blockquote> Al写道:
我还在尝试这样做,但它从未奏效过!
在一个.cpp文件中,我编写代码,并在开始时写道:
#ifndef MYLIST_H
#define MYLIST_H
...结束:
#endif
创建头文件有什么问题什么时候编译?
我是否需要在块中写下#include(s)?
你能告诉我预处理器的功能和功能吗?
这种模式通常用在头文件(.h)中。在.cpp文件中没有任何用处
。
头文件就是一些东西g由您创建,而不是通过编译。
其目的是声明符号的类型。其他cpp文件可以
#include头文件来共享声明。
-
Scott McPhillips [VC ++ MVP]
I''m still trying to do this but it never worked!
In a .cpp file, I write the code, and at the beginning, I write:
#ifndef MYLIST_H
#define MYLIST_H
....to end:
#endif
What''s wrong with it for creating a header file when compiling?
Do I need to write in the block the #include (s)?
Could you tell me more infos of what the preprocessor does and can do?
Hi,
It should work unless...
some header you include has the same MYLIST_H defined. Try to take a more
random name.
#includes can go anywhere (of course before you use anything from them) but
it makes sense to put them after the #ifndef to save some loading time (the
preprocessor would load the files and everytime your header files is
included somewhere.
--
Regards, Ron AF Greve
http://moonlit.xs4all.nl
"Al" <al************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...I''m still trying to do this but it never worked!
In a .cpp file, I write the code, and at the beginning, I write:
#ifndef MYLIST_H
#define MYLIST_H
...to end:
#endif
What''s wrong with it for creating a header file when compiling?
Do I need to write in the block the #include (s)?
Could you tell me more infos of what the preprocessor does and can do?
Could it depend on the compiler? I use Dev-C++.
Moonlit wrote:Hi,
It should work unless...
some header you include has the same MYLIST_H defined. Try to take a more
random name.
#includes can go anywhere (of course before you use anything from them) but
it makes sense to put them after the #ifndef to save some loading time (the
preprocessor would load the files and everytime your header files is
included somewhere.
Al wrote:I''m still trying to do this but it never worked!
In a .cpp file, I write the code, and at the beginning, I write:
#ifndef MYLIST_H
#define MYLIST_H
...to end:
#endif
What''s wrong with it for creating a header file when compiling?
Do I need to write in the block the #include (s)?
Could you tell me more infos of what the preprocessor does and can do?
This pattern is often used in header files (.h). It serves no purpose
in a .cpp file.
A header file is something that is created by you, not by compiling.
Its purpose is to declare the types for symbols. Other cpp files can
#include the header file to share the declarations.
--
Scott McPhillips [VC++ MVP]
这篇关于如何使用编译创建头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!