From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: inline operator bug ? Date: Fri, 04 May 2001 23:33:09 +0100 Lines: 44 Message-ID: References: <9cs1p9$a0d$2 AT info DOT cyf-kr DOT edu DOT pl> NNTP-Posting-Host: modem-120.californium.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news6.svr.pol.co.uk 989015572 31342 62.136.68.248 (4 May 2001 22:32:52 GMT) NNTP-Posting-Date: 4 May 2001 22:32:52 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Agent 1.7/32.534 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Rafal Maj" wrote: > I have found some problems with using inline operators and I think that it > might be a bug. > This bug can only be seen in projects, so my example program has 3 files : > ****** file bug1lib.h ****** > class cA { public : inline void operator +(int); } ; > ****** file bug1lib.cc ******* > #include "bug1lib.h" > inline void cA::operator +(int) { }; > ****** bug1m.cc ****** > #include "bug1lib.h" > int main() { cA a; a+2; } > > After building this project I get output like this : > Compiling: bug1lib.cc no errors > Compiling: bug1m.cc no errors > Creating: bug1.exe > Error: bug1m.o: In function `main': > Error: bug1m.cc(.text+0x10): undefined reference to `cA::operator+(int)' > Error: collect2: ld returned 1 exit status > > After removing inline from bug1lib.cc & bug1lib.h everything is working > correct. This is expected behaviour. To be inlined, the function must be visible at compile time whenever it is used. So the code can either be: ****** file bug1lib.h ****** class cA { public : void operator +(int) {/*...*/} } ; ****** bug1m.cc ****** #include "bug1lib.h" int main() { cA a; a+2; } or: ****** file bug1lib.h ****** class cA { public : void operator +(int); } ; inline void cA::operator +(int) {/*...*/}; ****** bug1m.cc ****** #include "bug1lib.h" int main() { cA a; a+2; }