473,769 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

friend sibling class nested in derived class problem in gcc 4.0

Hi all,
I'm in doubt with the following code:

class Base {
public:
class Nested {};
};
class Derived:public Base {
public:
class Nested {
public:
void m();
};
class AnotherNested {
friend class Nested; // gcc 4.0.2 takes it as 'Base::Nested'
//friend class Derived::Nested ; // this is needed in order to
be compiled by gcc 4.0.2
#line 14
AnotherNested() {}
};
};
void Derived::Nested ::m() {
#line 18
Derived::Anothe rNested instance;
}

should the first friend decl refer to Base::Nested or Derived::Nested ?

The code is refused e.g. by gcc 4.0(.0,.2):
a.cpp: In member function 'void Derived::Nested ::m()':
a.cpp:14: error: 'Derived::Anoth erNested::Anoth erNested()' is private
a.cpp:18: error: within this context
because gcc 4 takes for granted the friend refers to Base::Nested.
However, e.g. gcc 3.4 takes it as Derived::Nested .
Declaring the friend the second way:
friend class Derived::Nested ;
works in gcc 4.0, but I see two issues with it:
1) it uses not-yet-fully-declared class Derived
2) some compilers (e.g. VC 6.0) can't compile it (because of the
Derived incompletness)

I've not succeeded tracking this issue neither in the C++ standard nor
in gcc.
best regards
Tomas Sieger

Dec 16 '05 #1
1 2130
FYI: this has been confirmed as bug in gcc:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25492
regards
Tomas Sieger

Dec 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2530
by: Asfand Yar Qazi | last post by:
Basically this: //file 'B.hh' class B { protected: void f() {} }; //file 'C.hh'
3
3498
by: cman | last post by:
#include <stdio.h> class Base { public: Base() { printf("Base()\n"); } ~Base()
5
1511
by: Charles Jamieson | last post by:
I have two classes, a base class, CBaseClass, and its derived class, CDerivedClass. I overload the insertion operator as ostream& operator << ( ostream&, CBaseClass& ); Then I define an object as CDerivedClass object;
3
1918
by: Alicia | last post by:
Hello, I am trying to figure out how to call an overloaded operator<< inherited from a base class. #ifndef PHONECALL #define PHONECALL #include "time.h" #include "interval.h"
1
1565
by: question | last post by:
I want to know incase there is any performance difference or overhead in calling a base class method and a derived class method. Basically I am talking about simple method that is not overridden nor virtual. If I declare a method in the base class say M1() and another in derived class M2(). Then I make a derived class object derived. I then invoke these: derved.M1() derived.M2()
8
2025
by: Mike C# | last post by:
Suppose I have a base class "foo". Another class, "bar" derives from it. Base class "foo" has a method called "rob_the_liquor_store()", and the inherited class "bar" overrides this method with one of its own, maybe specifying the liquor store over on 44th Street and 5th Avenue or something. Anyway this is what we have so far: base class: "foo" |------------method: "rob_the_liquor_store()" |
1
1399
by: Rahul | last post by:
Hi Everyone, I have the following code, class AA { public: int i; };
3
1979
by: Edan | last post by:
I have a base class with protected members (`Base`). The function `MakeBase()` is a member function of another class, that returns a `Base` object initialized with private members of this class. Now the thing is, I want to extend the functionality of `Base` class. I do that by inheriting `Base` class by `Derived`, but then I can't use `MakeBase()` function. It all makes sense to me, but I don't seem to find an appropriate solution. Since I...
0
1451
by: brboLikus | last post by:
Hello everybody! My problem is somewhat strange since I can't think of any normal situation where one would like to do what I need, but here it goes. I need to somehow cast a base class to a derived class, but from the base-class code. I would need to do something like this: class Base { public Base() { } public void Convert() {
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.