Hi,
I looked a while at this but couldnt convice myself of the following reasons in the code.
[code=cpp]
class A{
int a;
public:
A():a(0){}
void func() {int A::*ptr = &A::a;}
void func1() {int *ptr = &a;}
//void func2() {int *ptr = &A::a;}----> compiler complains
//void func3() {int A::*ptr = &a;}----> compiler complains
};
1. The compiler expects the dereference operator after the scope resolution operator as in (A::*ptr) but complains when i try to use the same convention like (A::&A). Does this has any specifc reason or it is that the implementor liked it this way (Me confused bcos the :: operator has a higher precedence in both the cases).
2. Does the func1() and func() differ in any way bcos of the use of (A::) operator in the func() definition. I suppose that the use of (A::) is redundant as it is implicit but I am doubtful bcos the compiler complains about func2() and func3().
why is that func2() and func3() are invalid syntax.
Thanks in advance.
gsi.
[/code]
I looked a while at this but couldnt convice myself of the following reasons in the code.
[code=cpp]
class A{
int a;
public:
A():a(0){}
void func() {int A::*ptr = &A::a;}
void func1() {int *ptr = &a;}
//void func2() {int *ptr = &A::a;}----> compiler complains
//void func3() {int A::*ptr = &a;}----> compiler complains
};
1. The compiler expects the dereference operator after the scope resolution operator as in (A::*ptr) but complains when i try to use the same convention like (A::&A). Does this has any specifc reason or it is that the implementor liked it this way (Me confused bcos the :: operator has a higher precedence in both the cases).
2. Does the func1() and func() differ in any way bcos of the use of (A::) operator in the func() definition. I suppose that the use of (A::) is redundant as it is implicit but I am doubtful bcos the compiler complains about func2() and func3().
why is that func2() and func3() are invalid syntax.
Thanks in advance.
gsi.
[/code]
Comment