This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with inline member functions

This mailing list is for discussing development *of* gcc, not help
using it. Your question would be appropriate on the 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
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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]