Topic: inline problem?


Author: chopps@water.emich.edu (Christian E. Hopps)
Date: 25 Jan 1995 19:33:50 GMT
Raw View
darrell pfeifer (pfeifer@camins.camosun.bc.ca) wrote:
>This code compiles on several other C++ compilers
>but doesn't work in CW5 (or earlier CW4).
>It gets an illegal inline error. Removing the inline
>keywork allows it to compile.

>class StringRep
> {
> friend Boolean operator == (const StringRep&, const StringRep&);
 ...
> };
>inline Boolean operator == (const StringRep& s1, const StringRep& s2)
> { ...

(The following was collected from the 2e of C++ PL's refernce manual)

Basically the operator is first declared in the friend declaration.
This gives the operator (or any function) *external* linkage
r.7.11.4:
 "A function first declared in a friend declaration is equivalent to
 an extern declaration (r.3.3, r.7.1.1)"

However, inline gives a default function internal linkage. (r.7.1.2)

I don't know what "default" means above however CW seems to be inconsistent
when treating things of similar nature e.g:

extern void j();  // explicit external linkage (7.1.1)
inline void j() {}  // CW illegal inline, this is you above.

void j();   // extern linkage (r.3.3 && r.7.1.1)
inline void j() {}  // ok by CW (hmm)

It seems to me after reading r.3.3 about 6 times that:

"inline void j() {}" above is equivelent to "static void j() {}"

except j() should try and be inlined if possible.

Whew.. heres a new fact I believe a recent ANSI/ISO resolution allows:
 extern inline void j() {}
perhaps this has something to do with the above?

Maybe someone else can help I cross-posted this to comp.std.c++, In the
meantime you can get around your problem by _defining_ your operator==()
at the point of declaration of friendship.

Chris.