R
Razvan
Hi,
I took a C++ test and I found the following question:
Q. Inside a class member function definition, which scope is searched
first when an unqualified variable is accessed?
1.Class static data
2.Global namespace data
3.Function local data
4.Current namespace data
5.Class member data
If I understand the question correctly I have to tell where
the compiler is looking for a variable when I use its symbol. To my
understanding the answer is "Function local data". That means that
inside a member function when I am using the variable myVar it will
first try to see if I have a local variable named myVar. If such a
variable does not exist then it will see if I have a member variable
myVar. If such one is not defined then it will look in the current
namespace and then in the global namespace.
So the 'scope' order is:
a. function local data
b. class member data (the same as static member data); I mean they are
both members of the class and the fact that the data is static or not
is irrelevant from this point of view (scope order evaluation)
c. current name space
d. global name space
Please correct me if I am wrong.
Regards,
I took a C++ test and I found the following question:
Q. Inside a class member function definition, which scope is searched
first when an unqualified variable is accessed?
1.Class static data
2.Global namespace data
3.Function local data
4.Current namespace data
5.Class member data
If I understand the question correctly I have to tell where
the compiler is looking for a variable when I use its symbol. To my
understanding the answer is "Function local data". That means that
inside a member function when I am using the variable myVar it will
first try to see if I have a local variable named myVar. If such a
variable does not exist then it will see if I have a member variable
myVar. If such one is not defined then it will look in the current
namespace and then in the global namespace.
So the 'scope' order is:
a. function local data
b. class member data (the same as static member data); I mean they are
both members of the class and the fact that the data is static or not
is irrelevant from this point of view (scope order evaluation)
c. current name space
d. global name space
Please correct me if I am wrong.
Regards,