C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

reflection in C++ methods

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
sandor
Guest





PostPosted: Thu Mar 17, 2005 9:50 pm    Post subject: reflection in C++ methods Reply with 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
Paul
Guest





PostPosted: Sat Mar 19, 2005 12:11 am    Post subject: Re: reflection in C++ methods Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.