Many macro levels

I need to write something like that in VS2008 C++ Compiler

#define g <iostream>
#include g

so the g in the #include is replaced with definition for g

I need it to help me in some auto generated code..
Or may be an alternative way..

Thanks
I don't think there is a way to do that in C++, but if you tell us a bit more about what you are trying to do, maybe we can come up with a solution.
I can do the following
1
2
3
4
5
6
7
8
9
#define IOSTREAM(file) #file
#include IOSTREAM(iostream)

int main()
{
    std::cout << "Hello\n";

    return 0;
}
Actually, I need to change the header and the class name with a #define..

something like that:

#define WorkingClass name

#include "WorkingClass.h"

void main()
{
WorkingClass object();

}

There is a ready-made program that generate .h files
And I have the main.cpp written to do some common work with this .h files...

so I need some way to change the main.cpp contents based on which .h file it must work on...


thanks
"void main()" is nonstandard and therefore nonportable.

void main()
Yes, alas, I know that this appears in many books. Some authors even argue that "void
main()" might be standard-conforming. It isn't. It never was, not even in the 1970s, in the
original pre-standard C.
Even though "void main()" is not one of the legal declarations of main, many compilers allow
it. What this means, however, is that even if you are able to write "void main()" today on your
current compiler, you may not be able to write it when you port to a new compiler. It's best to
get into the habit of using either of the two standard and portable declarations of main:
int main()
int main( int argc, char* argv[] )
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
#include <iostream>

class Foo1
{
public:
    void name()const{std::cout << "Foo1\n";}
};

class Foo2
{
public:
    void name()const{std::cout << "Foo2\n";}
};

#define USING_CLASS(className) typedef className Type;

USING_CLASS(Foo1)

int main()
{
    Type object;
    object.name();

    return 0;
}
How about using namespaces rather than changing the names of the classes?
Topic archived. No new replies allowed.