 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
sandor Guest
|
Posted: Thu Mar 17, 2005 9:50 pm Post subject: reflection in C++ methods |
|
|
Hi,
Is there any way (including whatever template/macro magic, or gcc
extensions) to find out in compile time whehter the current scope is
part of a non-static method, and the "this" keyword is valid in the
current scope?
I want something like this:
void log(void *_this, const char *);
void log(const char *);
void C::fn() // non-static method of a class
{
MAGIC_THING("asdf"); // this should call log(this, "asdf")
}
void fn() // global
{
MAGIC_THING("asdf"); // the same macro should call log("asdf")
}
It would be essential to use the same macro in both scopes, and no
changes should be needed to the enclosing classes (C in this example).
best regards,
Sandor
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Paul Guest
|
Posted: Sat Mar 19, 2005 12:11 am Post subject: Re: reflection in C++ methods |
|
|
Hello Sandor,
I think that the approach you have taken to this problem is slightly
off the mark .
If you want to use the log fn for classes as well as for other general
purposes , then , my suggestion is you pass T as param and call the fn
you have implemented in that class ie we have a log fn in each class
and the generic log can take any class as param and call the function
of that class.
Regards,
Dhiman.
sandor wrote:
| Quote: | Hi,
Is there any way (including whatever template/macro magic, or gcc
extensions) to find out in compile time whehter the current scope is
part of a non-static method, and the "this" keyword is valid in the
current scope?
I want something like this:
void log(void *_this, const char *);
void log(const char *);
void C::fn() // non-static method of a class
{
MAGIC_THING("asdf"); // this should call log(this, "asdf")
}
void fn() // global
{
MAGIC_THING("asdf"); // the same macro should call log("asdf")
}
It would be essential to use the same macro in both scopes, and no
changes should be needed to the enclosing classes (C in this
example).
best regards,
Sandor
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|