[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 12:56:36 +0200 |
User-agent: |
KNode/0.10.2 |
>> class Lit {
>> int x;
>> public:
>> Lit() : x(2*var_Undef) {} // (lit_Undef)
>> explicit Lit(Var var, bool sign = false) : x((var+var) + (int)sign)
>> { }
>> friend Lit operator ~ (Lit p) { Lit q; q.x = p.x ^ 1; return q; }
>>
>> friend bool sign (Lit p) { return p.x & 1; }
>> friend int var (Lit p) { return p.x >> 1; }
>> friend int index (Lit p) { return p.x; }
[...]
>> };
Armel Asselin wrote:
> to be honest your usage of friend seems a bit non-sense to me: friend is
> to make NON MENBER methods (static or not) able to access protected and
> private elements of a class. There you declare bunches of member
> functions as friend: simply remove all these unnecessary 'friend' first.
No he doesn't, they are plain, free functions, not memberfunctions.
However, it is nonetheless pretty backward compared with idiomatic C++
where indeed the typical way would be
class Lit {
bool sign() const { return x&1; }
bool var() const { return x>>1; }
[...]
};
This doesn't affect the OP's problem though.
Uli
--
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/