Article View: alt.comp.lang.learn.c-c++
Article #321Re: Template Linking Error
From: Richard Damon
Date: Tue, 17 Dec 2002 21:55
Date: Tue, 17 Dec 2002 21:55
79 lines
3532 bytes
3532 bytes
"Mike K" <mkipper@rogers.com> wrote:
>Hi,
>
>As an example, can someone please tell me why this won't work?
>
>IN HEADER.CPP
>------------------------------------------------------------
>#include "header.h"
>template <typename X, typename Y>
>A<X,Y>::A(void)
>{}
>
>template <typename X, typename Y>
>A<X,Y>::~A(void)
>{}
>------------------------------------------------------------
>
>IN HEADER.H
>------------------------------------------------------------
>#ifndef __HEADER_H_INCLUDED__
>#define __HEADER_H_INCLUDED__
>
>template <typename X, typename Y>
>class A
>{
>public:
> A();
> ~A();
>};
>
>#endif /* !defined(__HEADER_H_INCLUDED__) */
>------------------------------------------------------------
>
>IN MAIN.CPP
>------------------------------------------------------------
>#include "header.h"
>int main(void)
>{
> A<char, int> b;
> return 0;
>}
>------------------------------------------------------------
>
>
>ERROR MESSAGES
>------------------------------------------------------------
>Compiling...
>header.cpp
>Linking...
>main.obj : error LNK2001: unresolved external symbol "public: __thiscall
>A<char,int>::~A<char,int>(void)" (??1?$A@DH@@QAE@XZ)
>main.obj : error LNK2001: unresolved external symbol "public: __thiscall
>A<char,int>::A<char,int>(void)" (??0?$A@DH@@QAE@XZ)
>Debug/DELETE ME.exe : fatal error LNK1120: 2 unresolved externals
>Error executing link.exe.
>
>DELETE ME.exe - 3 error(s), 0 warning(s)
>------------------------------------------------------------
>
>
>Thanks for your help!
>
>Mike
When the compiler compiles header.cpp it doesn't know which version of A in
create. When it compiles mai.cpp it doesn't know how to instance A. The export
keyword is supposed to handle this, but almost no compilers support it in a
usable manner.
--
richard_damon@iname.com (Redirector to my current best Mailbox)
rdamon@beltronicsInspection.com (Work Adddress)
Richad_Damon@msn.com (Just for Fun)
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Technical Details
Message-ID:
<vf4vvu0andu51v08hfuv1i10sfnnjefooo@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mailReferences:
<5FyL9.7$Vnm1.2@news04.bloor.is.net.cable.rogers.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,6f410bd2455c5e2d,start X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,6f410bd2455c5e2d,start X-Google-Attributes: gid114592,public X-Google-Thread: 101289,6f410bd2455c5e2d,start X-Google-Attributes: gid101289,public X-Google-Thread: fc772,6f410bd2455c5e2d,start X-Google-Attributes: gidfc772,public X-Google-ArrivalTime: 2002-12-17 13:53:40 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail From: Richard Damon <Richard_Damon@hotmail.com> Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp,comp.lang.c++,comp.lang.c++.moderated Subject: Re: Template Linking Error Date: 17 Dec 2002 16:55:22 -0500 Organization: Beltronics Inc Lines: 79 Sender: cppmods@netlab.cs.rpi.edu Approved: kuehl@fmi.uni-konstanz.de Message-ID: <vf4vvu0andu51v08hfuv1i10sfnnjefooo@4ax.com> References: <5FyL9.7$Vnm1.2@news04.bloor.is.net.cable.rogers.com> Reply-To: rdamon@beltronicsinc.com NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: Tue, 17 Dec 2002 16:09:24 -0500 X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPf+dRkHMCo9UcraBAQECJwIAqO8j+ZTuJauBgbRCl/NwLqliEO4X6s0S 0awrPEouWyVxgSiMatQEw6JFNmZVeARUAEmgSfHQtmXxcey0fe8Faw== =iMpR