conditional compilation

G

Gary Wessle

Hi

I need to create an object of her_t OR his_t inside a namespace. the
choice should be decided based on a macro. did the following
accomplish this?

thank you.

// macro
// uncomment ONLY ONE of the 2 lines below
#define HIS
//#define HER


namespace s_inf
{
....

#ifdef HIS
his_t conn; // FXGame OR FXTrade
#endif

#ifdef HER
her_t conn;
#endif

....
}

the above created his_t and NOT her_t object. right?

// place in a ".h" file and #include it in ".cpp" file and use the
object "conn".
 
F

Frederick Gotham

Gary Wessle posted:
I need to create an object of her_t OR his_t inside a namespace. the
choice should be decided based on a macro.


#ifdef MALE
typedef his_t Type;
#else
#ifdef FEMALE
typedef her_t Type;
#else
#error "You must #define either MALE or FEMALE."
#endif
#endif

namespace MyNa {

Type obj;
}
 
R

red floyd

Frederick said:
Gary Wessle posted:



#ifdef MALE
typedef his_t Type;
#else
#ifdef FEMALE
typedef her_t Type;
#else
#error "You must #define either MALE or FEMALE."
#endif
#endif

namespace MyNa {

Type obj;
}

#if defined(MALE)
typedef his_t Type;
#elif defined(FEMALE)
typedef her_t Type;
#else
#error "You must #define either MALE or FEMALE
#endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top