| SatsumaBenji (167) | ||||||||
|
Ok this is a really interesting question that could be rather useful in the right situations but I'm not sure if it's possible. I've been doing a little reading on macros for something else when I came across "stringification". The tutorial says that if I define a macro to a certain value or string I can convert this macro to what it defines by using the '#'. i.e.
So... Is it possible to create classes using a the definition of the macro to setup the class name? i.e.
Would this work (if it works at all) with the same functionality as:
| ||||||||
|
Last edited on
|
||||||||
| Computergeek01 (2874) | |
The #define macro is basically a precompiler time find and replace operation. There's not too much about it that cool.
| |
|
|
|
| ResidentBiscuit (2651) | |
| How would you handle object creation? Or constructors? | |
|
Last edited on
|
|
| Disch (8617) | |||||
|
You mean for some kind of reflection? There wouldn't be much point to it. Closest you can do is this:
But as you can see that's pointless, because it has the same effects as this:
| |||||
|
|
|||||
| SatsumaBenji (167) | |||||
|
@Computergeek01 I know the #define is for setting up replacement macros but this is what I want it for.So basically I can create a class and as the program reads the macro it should be replaced by the compiler right?? So if I had:
The CLASSNAME macro should be completely replaced with "Object" shouldn't it? Thus giving the class definition the same functionality as:
I think this would work somehow but I'm not sure if it'd need the 'stringify #' or not? Or if it'd work at all? @ResidentBiscuit That's the beauty, I'm not wanting to use constructors and destructors for these classes. I plan to create derived classes which are basically just containers of a superclass with only values changed... Trust me I know a way how to make it work if I can do this! | |||||
|
Last edited on
|
|||||
| Disch (8617) | ||||||||
Yes but it will replace it literally with the string "Object" not with the name Object.IE this:
becomes this:
You probably meant to do this:
But again I really don't see the point to this because you can just use Object directly and not bother with the macro at all.EDIT: Also note you can't use the # stringize token outside of macros. They can only be used inside the #define itself. So this: cout << "Macro MAC contains: " << #MAC << endl; Would give you an error because # is being used outside of a macro definition. | ||||||||
|
Last edited on
|
||||||||
| ResidentBiscuit (2651) | |
| There's a great way to answer these kind of things; test it out. What's the point of this, though? | |
|
|
|
| Disch (8617) | ||
I've been wondering this as well. Still not sure what the OP is actually trying to do other than obfuscate his code with unnecessary macros. | ||
|
|
||
| SatsumaBenji (167) | |
|
@ResidentBiscuit Well yes I was planning to test it out but I was away from my computer when I wanted to know so I thought I'd ask if it was possible and if anybody had any tips or problems I may need to face first. @Disch Ah thanks for that, and trust me I have my uses! XD Basically I want a program that is practically nothing and in a way, practically compiles itself based on files in a specified directory. You might see if my project is one day complete. | |
|
|
|
| Disch (8617) | |
|
Don't all programs compile themselves in that sense? Still confused... but whatever. As long as you're enjoying what you're doing I guess it's fine. Don't let old farts like me dissuade you. :) | |
|
|
|