Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!ditka!comeau From: comeau@ditka.Chicago.COM (Greg Comeau) Newsgroups: comp.lang.c++ Subject: Re: Inline Isn't Message-ID: <40515@ditka.Chicago.COM> Date: 6 Jun 91 13:00:00 GMT References: <1666@msa3b.UUCP> Sender: comeau@ditka.Chicago.COM (Greg Comeau) Reply-To: comeau@csanta.attmail.com (Greg Comeau) Organization: Comeau Computing Lines: 28 In article <1666@msa3b.UUCP> kevin@msa3b.UUCP (Kevin P. Kleinfelter) writes: >When one declares a class in a .h file, and specifies the body of >a member function as inline in the .cpp file, do most compilers fail >to inline it? >/**** foo.h ******/ >class foo { private: int x; public: int bar (); }; >/***** foo.cpp ****/ >inline int bar () { return x; } >/***** other.cpp *****/ >#include "foo.h" >void demo (void) { int i; foo f; i = f.bar(); } First, recognize that inline is only a hint to the compiler (like register is) and not a mandate. Second, for something that's inline to have significance it must be visible to the translation unit that wants it inline'd. In a case like you've illustrated, one would typically put the definition for bar right into the class definition, that way the function isn't just a linker issue and is known to the compiler as an inline. - Greg -- Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418 Producers of Comeau C++ 2.1 Here:attmail.com!csanta!comeau / BIX:comeau / CIS:72331,3421 Voice:718-945-0009 / Fax:718-441-2310