Date: Tue, 7 Feb 1995 10:48:25 +0100 (CET) From: "Roland Exler" Sender: k3a0270 AT pop DOT uni-linz DOT ac DOT at Reply-To: R DOT Exler AT jk DOT uni-linz DOT ac DOT at To: Subject: Multiple definition ... using Templates Hi anybody, I've an simple-looking error linking from multiple modules each using the same instance of a template-class. In the example below 'main' and 'sub' uses class 'store' declared in file 'temp.h', both compile ok. Linking the files produces the 'multiple definition'-error as you can see in the appended file 'ERR.LOG' produced by redirecting the output of make. Can anybody tell me how to correct this error? Thanks, Roland +---------------------------------------+---------------------------+ I Roland Exler I EMAIL: I I Universitaet Linz I R DOT Exler AT jk DOT uni-linz DOT ac DOT at I I Institut fuer Elektrische Messtechnik I I I Altenbergerstr. 69 I Phone: I I A-4040 Linz, AUSTRIA I + 43 732 2468 9205 I +---------------------------------------+---------------------------+ ************************ File TEMP.H ******************************** #ifndef _TEMP_H #define _TEMP_H template class store { protected: TYPE data; public: store(TYPE daten) {data=daten;}; TYPE read(); }; template TYPE store::read() { return data; } #endif ************************ File MAIN.CC ******************************** #include #include "temp.h" void sub(); int main() { store one(1); store two(2); cout<<"main: "< #include "temp.h" void sub() { store one(1); store two(2); cout<<"sub: "<::read(void)' main.cc(.text+0x70): first defined here make.exe: *** [main] Error 1