GCC 4.1.0 compile error
Pranabesh Dash
pranabesh.dash@gmail.com
Fri Mar 16 21:31:00 GMT 2007
On 3/16/07, Pranabesh Dash <pranabesh.dash@gmail.com> wrote:
>
> Hi,
> The following piece of code compiles fine with 3.4.2, 4.0.0 but errors out on 4.1.0. Seems like a GCC bug. The friend function name is recognized if called as a function but does not work when used as a function pointer. An explicit function declaration (or definition reordered) is needed to get it to compile with 4.1.0.
>
> Do you believe this is a bug or a feature???
>
> --P.D
>
> #include <iostream>
>
> using namespace std;
>
> class object;
> typedef void (func_ptr)( object* );
> class object {
>
> public:
> object() {}
> ~object() {}
>
> void top_func();
> void call_func_ptr(func_ptr);
> protected:
> friend void frnd_func(object*);
>
> private:
> int member;
> };
>
> //friend.cpp: In member function #void object::top_func()#:
> //friend.cpp:27: error: #frnd_func# was not declared in this scope
> // The following needs to be uncommented to get 4.1.0 to compile
> //void frnd_func(object*) ;
>
> void object::top_func() {
> frnd_func(this); // Does not complain on this
> call_func_ptr(frnd_func); // But complains on this !!!!!
> }
>
> void object::call_func_ptr(func_ptr fp) {
> fp(this);
> }
>
> void frnd_func(object* obj) {
> obj->member = 4;
> }
>
> main () {
>
> object my_obj;
> }
>
More information about the Gcc-help
mailing list