C++ namespace::class can't be friends with main()

Dean Foster foster@diskworld.wharton.upenn.edu
Wed Dec 22 18:06:00 GMT 1999


Possibly I'm being really stupid.  But I'm pretty sure the following
is a bug.  main() should be able to access the protected constructor
since it is a friend.  (Note: I've also run into other problems making
functions friends, but this is the only one that I'm sure isn't my
error!) 

thanks,

dean
-----------------------------------------------------------------------

namespace foo
{
  class bar
  {
  protected:
    bar();
  private:
    friend int main();  // should make main() a friend
                        // note: "friend int ::main()"  doesn't work either
                        // pre-declaring main doesn't help
  };

}
 
int
main()
{
  foo::bar x;
}
-----------------------------------------------------------------------
output:
friends.cc: In function `int main()':
friends.cc:8: `foo::bar::bar()' is protected
friends.cc:18: within this context
-----------------------------------------------------------------------
version:
Reading specs from
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
-----------------------------------------------------------------------



More information about the Gcc-bugs mailing list