Question on dynamic casting scope

Philippe Bouchard philippeb@corel.com
Tue Nov 21 07:33:00 GMT 2000


The following program:
#include <iostream>
int main();
struct A
{
  virtual ~A() {}
};
struct B
{
  virtual ~B() {}
};
struct O : A, private B
{
  friend int main();
  virtual ~O() {}
};
int main()
{
  using namespace std;
  A * p = new O;
  cout << "A * = " << dynamic_cast<A *>(p) <<
endl;
  cout << "B * = " << dynamic_cast<B *>(p)
<< endl;
  cout << "O * = " << dynamic_cast<O *>(p)
<< endl;
}
Outputs:
A * = 0x8049fd0
B * = (nil)
O * = 0x8049fd0
Notice:
If I the inheritance of B into O becomes public, the address of B *
becomes 0x8049df4.
Question:
I was wondering why friendship is not affecting dynamic casting scope.
Thank you.
 
begin:vcard 
n:Bouchard;Philippe
x-mozilla-html:FALSE
org:Corel Linux
adr:;;;;;;
version:2.1
email;internet:philippeb@corel.com
title:Software Engineer
x-mozilla-cpt:;0
fn:Philippe Bouchard
end:vcard


More information about the Gcc-bugs mailing list