I wonder if I have something like this where Replace is the same as/"contains":
Number == 5.
My question is if it is possible to put this: Number == 5 to a std::string in any way through Replace ?
Code:#define Replace Number == 5
I wonder if I have something like this where Replace is the same as/"contains":
Number == 5.
My question is if it is possible to put this: Number == 5 to a std::string in any way through Replace ?
Code:#define Replace Number == 5
So you want to do something likeand you actually want that to beCode:if (Replace) dosomething;Yes, you can do that - I wouldn't exactly recommend it, and it may cause all sorts of interesting problems when you mix it with other things if you're not careful.Code:if(Number == 5) dosomething;
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Yes. I beleive I am trying to put to a std::string so I tried something like this.
I think ´Word´ is containing "Number == 5" as a std::string now ?
Thanks...
Code:#define ReplaceS "Number == 5" std::string Word; Word = ReplaceS;
Yes.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
"abusing define"? Sounds dramatic, like it might end all life as we know it.
Mainframe assembler programmer by trade. C coder when I can.
I am trying out to do it through define because I cant see any other solution for what I have to do. I am doing it with causion and a lot of testing and no one except me will read the code so that will be no problem anyway.
Just because you can get away with it doesn't mean it's right. I dare say 100% of things can be done without macros of this type. I have never, ever needed such a macro during my programming career.
I suggest you explain what you're trying to do and show some code and people can suggest alternatives.
What is it that you actually want to achieve?
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
I agree that it's not a particularly good thing to do. What are you ACTUALLY trying to do, perhaps if you explain the bigger picture we can come up with something that works better?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks, I will try to explain what I am doing.
I have a Form application where I wrote this:
Then I have created a new Item to my project named Item1.hCode:#include "Item1.h" int Number = 5; if( Criteria ) { int i = 1; }
Here I have written this:
I cant think of any other solution of how to do this. This is ofcourseCode:#define Criteria Number == 5
the only way to do it as I dont know any other way though.
The thing is that I have to in any way write this code in Item1.h.
Last edited by Coding; 03-12-2008 at 02:31 PM.
Now I know that you dont like that I am doing an "own" language within the language but this is working if you are very careful.
This is what I am doing and have to do. So I will use an emty .h file where other people can code in this "own" language without interacting inside the C++ code where all thousands of lines are.
They will just concentrate to write things in Item.h.
This is the whole reason why. These people dont know C++.
I also agree that it feels wrong to use define.
So I dont know if it could be possible in any way to do what I am trying to do ?
Last edited by Coding; 03-12-2008 at 02:40 PM.
If people don't know C++, then they shouldn't be coding at all. Come on, Coding.
If you want to make a scripting language for people, then write a parser or interpreter.
Just because someone doesn't know C++ doesn't mean you should try to abstract away the syntax. They should learn C++, you should not try to make them get away with it.
If everyone used different syntax for creating C++, no one would understand someone else's code here. A total mess (which is essentially what you're trying to invent).
Ubuntu Desktop
GCC/G++
Geany (for quick projects)
Anjuta (for larger things)