help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wierd friend behaviourin g++ 4.1.1


From: Ulrich Eckhardt
Subject: Re: Wierd friend behaviourin g++ 4.1.1
Date: Sun, 18 Jun 2006 13:02:14 +0200
User-agent: KNode/0.10.2

Paulo Matos wrote:
> class Lit {
>     friend Lit  toLit (int i) { Lit p; p.x = i; return p; } 
[...]
> };
> 
> class GClause {
[...]
>     Lit         lit      () const { return toLit(((int)data) >> 1); }
[...]
> };

I think this is close to a minimal example which is YOUR job to provide as
common courtesy.

> The error is:
> $ g++ -Wall --std=c++98 -c  lit_friend.cc
> lit_friend.cc: In member function 'Lit GClause::lit() const':
> lit_friend.cc:39: error: 'toLit' was not declared in this scope
> 
> toLit is a global friend function defined inside Lit. 

Right, it is. However, and that is where you'd have to consult someone that
knows the standard much better, I'm not sure if it was also globally
declared!

Pretty obvious, adding a declaration at the global namespace should do the
job.

> I don't think I can define it outside lit since that would generate
> problems. 

Why?

> Defining after Lit would make the friend declaration  
> inside Lit invalid since the function would not be already defined.

Wrong.

> Defining it before Lit would render the argument of the function
> undefined and an incomplete declaration like: "class Lit;" would not
> work.

True. Apart from that, how about passing by (const) reference?

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]