This mailing list is for discussing development *of* gcc, not help
using it. Your question would be appropriate on the
gcc-h...@gcc.gnu.org list, please take any follow-up there, thanks.

On 7 February 2012 13:57, Alexandre Almeida wrote:
>
> It seems to be impossible to define an inline member function externally with 
> GCC. When attempting to do so, the linker returns an error.

Yes, see http://www.parashift.com/c++-faq/inline-functions.html#faq-9.7
You can't do that. It wouldn't be inline if it's external.


> Here is how I attempted to do it:
>
> Header file:
> -----------------
> class C
> {
> public:
>     void foo();
> };
>
> CPP file:
> -------------
> inline void C::foo()
> {
>     [...]
> }

In the .cpp file the compiler sees the function is never used so
doesn't bother generating code for it.

The C++ standard requires that an inline function is defined in every
file that uses it (that's what makes it "inline"). When compiling the
.cpp file the compiler knows that the function isn't used in that
file, and knows that it must be defined in any other file that needs
it (because that's what the standard requires) so there is no need to
generate code for the inline function in that file.

Reply via email to