This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with inline member functions
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Alexandre Almeida <meta dot lx at hotmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 7 Feb 2012 15:22:18 +0000
- Subject: Re: Problem with inline member functions
- References: <BLU161-W567380A85DD18AA78E040BE8750@phx.gbl>
This mailing list is for discussing development *of* gcc, not help
using it. Your question would be appropriate on the
gcc-help@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.