Accessing the caller

Sep 8, 2010 at 1:01pm
Hello.I am wondering how can we determine type of tne caller?Any Idea?
Sep 8, 2010 at 1:29pm
I think the caller would have to pass a reference to itself as a parameter to the called function.
Sep 8, 2010 at 1:43pm
then the type of the caller will be problematic
Sep 8, 2010 at 2:36pm
templates
Sep 8, 2010 at 2:46pm
Thank you

u helped me a lot
Sep 8, 2010 at 2:52pm
What exactly are you trying to achieve?
Sep 8, 2010 at 2:53pm
What exactly are you trying to achieve?


^ This.

It sounds like you're doing something very wrong.
Sep 8, 2010 at 4:34pm

Galk wrote:
What exactly are you trying to achieve?


I want to give each user an access privilage to do only some action \s which others cannot do
Sep 8, 2010 at 4:55pm
I think you need some kind of user object that is created on login and is either passed to every function or made available by some other means. Perhaps a singleton. Or possibly a member variable passed to the constructor of classes that require this type of access control.
Sep 8, 2010 at 5:05pm
Don't pass the type of the caller to the function... or try to determine the type from the called function. Both of these are bad design as they require the called function to be aware of the calling type.

This is bad because:
- it requires the function to be aware of all possible types that can call the function
- it makes it difficult to add new types in the future
- it assumes that the calling function even has a type (what if it is being called from a static/global function?)


A better approach would be to have some kind of access level variable and pass that to the function.
Sep 10, 2010 at 6:56am
Thank you all.

Disch, you helped me a a lot.

I will do it through a session created when the user logs on.The session has a member userType, as has "User", set when "User"logs in.The User does almost every action through a session, so I check the userType.

Topic archived. No new replies allowed.