What's the usage? 
July 22nd, 2005, 10:01 AM
| | | |
What's the usage of #ifdef and #endif in the code below?
#ifdef C_DEF
class C
{
public:
void Repair();
};
void C::Repair () {
....
}
#endif
Since I understand using like:
#ifdef C_DEF
class C
{
public:
void Repair();
};
#endif
void C::Repair () {
....
}
Thanks! | 
July 22nd, 2005, 10:01 AM
| | | | re: What's the usage?
"ikl" <ikl72@dsp.com> wrote in message
news:PMscc.26067$vo5.826762@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> What's the usage of #ifdef and #endif in the code below?
>
> #ifdef C_DEF[/color]
if the symbol 'C_DEF' is defined (with a #define directive),
then translate all the following code...
[color=blue]
> class C
> {
> public:
> void Repair();
> };
>
> void C::Repair () {
> ...
> }[/color]
.... until a
[color=blue]
> #endif[/color]
... directive is encountered.
[color=blue]
>
> Since I understand using like:
>
> #ifdef C_DEF
> class C
> {
> public:
> void Repair();
> };
> #endif[/color]
This is the same as above, except it doesn't
include the definition of the member function
'Repair()'.
[color=blue]
>
> void C::Repair () {[/color]
A class 'C' must be visible at this point for
this to be valid.
[color=blue]
> ...
> }[/color]
Look up 'preprocessor directives' in your C++ book.
-Mike | 
July 22nd, 2005, 10:01 AM
| | | | re: What's the usage?
"ikl" <ikl72@dsp.com> wrote in message
news:PMscc.26067$vo5.826762@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> What's the usage of #ifdef and #endif in the code below?
>
> #ifdef C_DEF[/color]
if the symbol 'C_DEF' is defined (with a #define directive),
then translate all the following code...
[color=blue]
> class C
> {
> public:
> void Repair();
> };
>
> void C::Repair () {
> ...
> }[/color]
.... until a
[color=blue]
> #endif[/color]
... directive is encountered.
[color=blue]
>
> Since I understand using like:
>
> #ifdef C_DEF
> class C
> {
> public:
> void Repair();
> };
> #endif[/color]
This is the same as above, except it doesn't
include the definition of the member function
'Repair()'.
[color=blue]
>
> void C::Repair () {[/color]
A class 'C' must be visible at this point for
this to be valid.
[color=blue]
> ...
> }[/color]
Look up 'preprocessor directives' in your C++ book.
-Mike | 
July 22nd, 2005, 10:01 AM
| | | | re: What's the usage?
#ifdef and #endif are used for conditional compilation.
If C_DEF is defined, then compile in the class C and its
public member functions.
If C_DEF is not defined, then class C is
not included. Then of course you dont want to include
the
void C::Repair () {
....
}
member function, since its an error.
[color=blue]
> What's the usage of #ifdef and #endif in the code below?
>
> #ifdef C_DEF
> class C
> {
> public:
> void Repair();
> };
>
> void C::Repair () {
> ...
> }
> #endif
>
> Since I understand using like:
>
> #ifdef C_DEF
> class C
> {
> public:
> void Repair();
> };
> #endif
>
> void C::Repair () {
> ...
> }
>
>
> Thanks!
>
>[/color] | 
July 22nd, 2005, 10:01 AM
| | | | re: What's the usage?
#ifdef and #endif are used for conditional compilation.
If C_DEF is defined, then compile in the class C and its
public member functions.
If C_DEF is not defined, then class C is
not included. Then of course you dont want to include
the
void C::Repair () {
....
}
member function, since its an error.
[color=blue]
> What's the usage of #ifdef and #endif in the code below?
>
> #ifdef C_DEF
> class C
> {
> public:
> void Repair();
> };
>
> void C::Repair () {
> ...
> }
> #endif
>
> Since I understand using like:
>
> #ifdef C_DEF
> class C
> {
> public:
> void Repair();
> };
> #endif
>
> void C::Repair () {
> ...
> }
>
>
> Thanks!
>
>[/color] | 
July 22nd, 2005, 10:03 AM
| | | | re: What's the usage?
JaSeong Ju wrote:
<A top-posted message.>
Please stop top-posting. Read section 5 of the FAQ (which you should
have already read) for posting guidelines: http://www.parashift.com/c++-faq-lite/
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting. | 
July 22nd, 2005, 10:03 AM
| | | | re: What's the usage?
JaSeong Ju wrote:
<A top-posted message.>
Please stop top-posting. Read section 5 of the FAQ (which you should
have already read) for posting guidelines: http://www.parashift.com/c++-faq-lite/
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|