Pre processor Directive Question

Jul 28, 2010 at 7:22pm

I am wondering how i can use a pre processor directive to replace strings.

in the code mentioned below:

i want to something like this:

#define yours::c my::a

i want to inherit my class from class a in namespace a if TEST is defined.

i am getting compilation errors for the macro i defined.

any help is appreciated.


/***************************************************/


#ifdef TEST
#define yours::c my::a
#endif
namespace my
{
class a
{
public:
virtual ~a() {};
virtual void create() =0;
};
}

namespace yours
{
class c
{
public:
virtual ~c() {};
};

}

namespace theirs
{

class d: public yours::c
{
public:
virtual ~d() { };
void create(){ cout<<"this is d create"<<endl;}
};



}
int main()
{
theirs::d *dobj = new theirs::d;
//dobj->
dobj->create();
return 0;
}
/*************************************************************/


Jul 28, 2010 at 8:00pm
You could first #define MINE_A mine::a then #define yours::c MINE_A

but it sounds to me like you actually can't assign values to pre-existing objects.
I think that if you want to do that you will have to make const variables at the beginning of your program, between the preprocessor and main()

and I also think that the preprocessor cannot handle classes that don't exist before the preprocessor directives. That is why it is called preprocessor...I think.
Last edited on Jul 28, 2010 at 8:04pm
Jul 28, 2010 at 8:43pm
Is this any good to you?

1
2
3
4
5
6
7
namespace yours {

int wibble;

}

namespace mine = yours;
Last edited on Jul 28, 2010 at 8:44pm
Topic archived. No new replies allowed.