Objectmix
Tags Register Mark Forums Read

declaring class member functions as friend without full class definition : c++

This is a discussion on declaring class member functions as friend without full class definition within the c++ forums in Programming Languages category; Hello, I am attempting to change a existing large code base and I have this situation: A.hpp class A { .... friend void B::member_function1() const; ... }; When I include B.hpp for the definition of B, I seem to fall in cross-include situation where the include guards don't work (or work bad...) I tried forward declaring class B before A, but it seems the full definition of B is required to declare its member function as a friend to A. Is there a solution to this? regards,...


Object Mix > Programming Languages > c++ > declaring class member functions as friend without full class definition

c++ comp.lang.c++ usenet archive

Reply

 

LinkBack Thread Tools
  #1  
Old 11-11-2008, 04:19 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default declaring class member functions as friend without full class definition

Hello,

I am attempting to change a existing large code base and I have this
situation:

A.hpp
class A {
....
friend void B::member_function1() const;
...
};


When I include B.hpp for the definition of B, I seem to fall in
cross-include situation where the include guards
don't work (or work bad...)

I tried forward declaring class B before A, but it seems the full definition
of B is required
to declare its member function as a friend to A.

Is there a solution to this?

regards,


Reply With Quote
  #2  
Old 11-11-2008, 05:22 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: declaring class member functions as friend without full class definition

On 2008-11-11 16:19:07 -0500, "Hicham Mouline" <hicham@mouline.org> said:

> Hello,
>
> I am attempting to change a existing large code base and I have this
> situation:
>
> A.hpp
> class A {
> ....
> friend void B::member_function1() const;
> ...
> };
>
>
> When I include B.hpp for the definition of B, I seem to fall in
> cross-include situation where the include guards
> don't work (or work bad...)
>
> I tried forward declaring class B before A, but it seems the full definition
> of B is required
> to declare its member function as a friend to A.
>
> Is there a solution to this?
>


Sure. Put the full definition of B before the definition of A. Since
you haven't shown any other code, it's impossible to guess the causes
of whatever other problems you've been running into.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Reply With Quote
Reply

Thread Tools



All times are GMT -5. The time now is 04:27 AM.