M
moogyd
Hi,
I am a C++ newbie, and have aa C++ project that compiles with the -
ffriend-injection (g++) option.
I am trying to understand what this option actually does, so that I
can fix the code. Unfortunately, google provides lots of descriptions
based on templates. that are way above my level of understanding.
I therefore created a very simple example:
namespace myNamespace {
class myClass {
friend int compute(myClass arg) {} ;
} ; // myClass
// If compute is not declared here, then I need the g++
// -ffriend-injection option
int compute(myClass arg);
} // myNamespace
int main() {
myNamespace::myClass myVar ;
myNamespace::compute(myVar) ;
return 0 ;
}
This compiles without -ffriend_injection. If I comment the
declaration int compute(..). then the option is required.
Without the namespece, it always compiles.
Therefore, it seems to me that friend injection means that
- all friend functions automatically become visible in the surrounding
namespace (myNamespace in this example)
Is this correct? Can anyone supply a (or a link to) a very simple
explanation.
Thanks,
Steven
I am a C++ newbie, and have aa C++ project that compiles with the -
ffriend-injection (g++) option.
I am trying to understand what this option actually does, so that I
can fix the code. Unfortunately, google provides lots of descriptions
based on templates. that are way above my level of understanding.
I therefore created a very simple example:
namespace myNamespace {
class myClass {
friend int compute(myClass arg) {} ;
} ; // myClass
// If compute is not declared here, then I need the g++
// -ffriend-injection option
int compute(myClass arg);
} // myNamespace
int main() {
myNamespace::myClass myVar ;
myNamespace::compute(myVar) ;
return 0 ;
}
This compiles without -ffriend_injection. If I comment the
declaration int compute(..). then the option is required.
Without the namespece, it always compiles.
Therefore, it seems to me that friend injection means that
- all friend functions automatically become visible in the surrounding
namespace (myNamespace in this example)
Is this correct? Can anyone supply a (or a link to) a very simple
explanation.
Thanks,
Steven