E
Exits Funnel
Consider this code which is a very trimmed down version of some I've
inherited and am trying to port from windows to g++:
//Begin test1.cpp
class foo { int i; int j; };
class bar
{
bar (int foo::* dataMember)
ffsetof (foo, *dataMember) //Call this Line (A)
{
// int i = offsetof (foo, *dataMember); //Call this Line (B)
}
};
//End test1.cpp
when I try to compile test1.cpp with g++, the compiler has this to say:
test2.cpp: In constructor `bar::bar(int foo::*)':
test2.cpp:6: syntax error before `;' token
A couple of questions then:
(1) Should the compiler complain? I don't have much experience with
using the 'pointer to data member' stuff, but based on the research I've
just done on the net, the code seems reasonable.
(2) If I move the call from the initializer list to the ctor body by
commenting out line (A) and uncommenting line (B), the compiler error
becomes:
test2.cpp: In constructor `bar::bar(int foo::*)':
test2.cpp:8: syntax error before `;' token
test2.cpp:8: declaration of `dataMember' shadows a parameter
test2.cpp:8: syntax error before `;' token
So, it seems the original problem persists which is reasonable but now
there's this additional shadowing issue. It's not clear to me what
parameer 'dataMember' is shadowing here? If anyone could explain this
to me it would be great.
Thanks in advance for any feedback!
-exits
inherited and am trying to port from windows to g++:
//Begin test1.cpp
class foo { int i; int j; };
class bar
{
bar (int foo::* dataMember)
ffsetof (foo, *dataMember) //Call this Line (A)
{
// int i = offsetof (foo, *dataMember); //Call this Line (B)
}
};
//End test1.cpp
when I try to compile test1.cpp with g++, the compiler has this to say:
test2.cpp: In constructor `bar::bar(int foo::*)':
test2.cpp:6: syntax error before `;' token
A couple of questions then:
(1) Should the compiler complain? I don't have much experience with
using the 'pointer to data member' stuff, but based on the research I've
just done on the net, the code seems reasonable.
(2) If I move the call from the initializer list to the ctor body by
commenting out line (A) and uncommenting line (B), the compiler error
becomes:
test2.cpp: In constructor `bar::bar(int foo::*)':
test2.cpp:8: syntax error before `;' token
test2.cpp:8: declaration of `dataMember' shadows a parameter
test2.cpp:8: syntax error before `;' token
So, it seems the original problem persists which is reasonable but now
there's this additional shadowing issue. It's not clear to me what
parameer 'dataMember' is shadowing here? If anyone could explain this
to me it would be great.
Thanks in advance for any feedback!
-exits