From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: template problem in djgpp Date: Sun, 10 Jun 2001 23:41:39 +0100 Lines: 40 Message-ID: References: <9fvfgf$obj$1 AT news DOT lth DOT se> NNTP-Posting-Host: modem-55.fermium.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newsg2.svr.pol.co.uk 992212898 31986 62.136.69.183 (10 Jun 2001 22:41:38 GMT) NNTP-Posting-Date: 10 Jun 2001 22:41:38 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 "Tomas Nilsson" wrote: > Hello, > I have a problem with templates i djgpp 2.03. I have tried the following > program: Put the class declaration *and* implementation in the header: > file class1.h: > template > class class1 { > private: > TYPE T; > public: > void f1(); > }; > template void class1::f1() {} > > file main.cpp > #include"class1.h" > int main() { > class1 c1; > c1.f1(); > } > > The program compiles without errors and warnings, but then something goes > wrong in the > linking process. The linker ld in djgpp returns the error message "undefined > reference to class::f1(void)". This is very strange, because the UNIX > compiler CC can compile and build this program without any problem, and CC > one of the best approximation of the C++ standard I know. > Can anyone see what could be causing this problem gcc needs to see the class definition at compile time, otherwise class1 does not exist at link time. > and why it works in CC and not djgpp? gcc DTRT here, so strictly speaking the other CC is buggy.