Topic: global scope cannot access ...


Author: jvsb@ra.alcbel.be (Johan Vanslembrouck)
Date: 9 Feb 94 10:11:35 GMT
Raw View
Consider the following program:

--------------------------------------------------------------------------

#include <iostream.h>

class Class
{
 friend class FriendClass;
  private:
 int c1;
 short c2;
};

class FriendClass
{
  public:
 static void* array[];
};

void* FriendClass::array[] =
{
 (void *) & ((Class *) 0) -> c1,
 (void *) & ((Class *) 0) -> c2
};

main()
{
 for (int i = 0; i < 2; i++) cout <<  FriendClass::array[i] << endl;
 return 0;
}

--------------------------------------------------------------------------

When compiling it using cfront-based compilers, I get the following errors:

"try11.cc", line 18: error:  global scope cannot access Class::c1:
private  member
"try11.cc", line 18: error:  global scope cannot access Class::c2:
private  member

It does compile, however, with Borland 3.1.

Who's right in this case? I think Borland. FriendClass is after all a
friend
of Class.


-----------------------------------------------------------------------
Johan Vanslembrouck - SE99                 Tel    : +32 3 2407739
Alcatel Bell Telephone                     Telex  : 72128 Bella B
Francis Wellesplein  1                     Fax    : +32 3 2409932
B-2018 Antwerp                             e-mail : jvsb@ra.alcbel.be
Belgium
-----------------------------------------------------------------------