Accessing the caller

Hello.I am wondering how can we determine type of tne caller?Any Idea?
I think the caller would have to pass a reference to itself as a parameter to the called function.
then the type of the caller will be problematic
templates
Thank you

u helped me a lot
What exactly are you trying to achieve?
What exactly are you trying to achieve?


^ This.

It sounds like you're doing something very wrong.

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
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.
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.
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.