overloading macro
I've a macro called $_SESSION()
and if one argument is passed to it it will invoke the getter method
and if two arguments has been passed it will invoke the setter
The '$' prefix leads me to believe that you're dealing with PERL, PHP or an SH variant. Since PHP and SH have no macros and PERL 6 macros don't look like that, I'm left to wonder, what are you talking about?
no I want to make a $_SESSION() macro which will behave like PHP's $_SESSION and abstract other Complex CGI Librery method Calls
In which language?
Going out on a limb and assuming C or C++, it's not possible. First the name cannot start with $, and secondly macros cannot be overloaded.
Going out on a limb and assuming C or C++, it's not possible. First the name cannot start with $, and secondly macros cannot be overloaded.
Right. That's not much better, but at least we got something to work with:
function session(){ $args = func_get_args(); if (count($args) == 1) return get_value($args[0]); if (count($args) == 2) return set_value($args[0], $args[1]); assert (false);}// Warning: not a superglobal!$_MY_SESSION = 'session';
Man why you are not understanding
#define $_SESSION(k) session::get(k)
#define $_SESSIOn(k, v) session::add(k, v)
but compiler warns that multiple defenition of $_SESSION macro
C++ doesn't forbids macros starting with $
#define $_SESSION(k) session::get(k)
#define $_SESSIOn(k, v) session::add(k, v)
but compiler warns that multiple defenition of $_SESSION macro
C++ doesn't forbids macros starting with $
Quote:Original post by nlbsWell, it's been five messages already in this thread, and even though I mentioned in the first message that you didn't specify the language you were enquiring about, you've waited until now to mention C++. Why have you not mentioned that earlier, thereby saving me the wasted time of proposing a PHP solution?
Man why you are not understanding
Seriously, you're just wasting everyone's time. The reason why you don't get the correct answer is because you suck at asking questions.
Quote:but compiler warns that multiple defenition of $_SESSION macro
Macros cannot be overloaded. Use a different solution, for instance create a class with an overloaded operator[] returning an object with an impicit conversion (that calls get) and an assignment operator (that calls set).
Quote:C++ doesn't forbids macros starting with $It does, '$' is only allowed as a microsoft extension.
Sorry as its mainly a C++ forum I thought its not required to say C++ explecitely
ok so if it cant be overloaded how can i make a macro that can accept one argument as well as two argument too.
I am using g++ and I've 4-5 macro's already running well who's name starts with $ sign.
ok so if it cant be overloaded how can i make a macro that can accept one argument as well as two argument too.
I am using g++ and I've 4-5 macro's already running well who's name starts with $ sign.
Quote:
Man why you are not understanding
Don't be rude to people trying to help you. You're original questions are far too vague; we don't read minds here.
Quote:
but compiler warns that multiple defenition of $_SESSION macro
Because you cannot overload macros. They are part of the preprocessor, and exist for simple, naive textual substitution.
Quote:
ok so if it cant be overloaded how can i make a macro that can accept one argument as well as two argument too.
You can't, the macros have to have different names. You can also use a function (an actual, honest C++ function) which can be overloaded.
Quote:
C++ doesn't forbids macros starting with $...I am using g++ and I've 4-5 macro's already running well who's name starts with $ sign.
Yes it does, '$' is not in the basic source character set. Visual C++ and some other compilers (including GCC) will let you use the character in an identifier as a language extension. If you disable extensions then it should provide you with an error (if it doesn't, the compiler is non-compliant with the C++ standard on that point).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement