From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30772 invoked by alias); 27 Aug 2004 11:16:57 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 30754 invoked from network); 27 Aug 2004 11:16:55 -0000 Received: from unknown (HELO applibk.profile.co.at) (193.83.21.2) by sourceware.org with SMTP; 27 Aug 2004 11:16:55 -0000 Received: from jupiter.profile.co.at (jupiter.profile.co.at [193.83.20.5]) by applibk.profile.co.at (8.12.8/8.12.8) with ESMTP id i7RBGsxq023732; Fri, 27 Aug 2004 13:16:54 +0200 Received: from [193.83.20.37] (dione.profile.co.at [193.83.20.37]) (authenticated bits=0) by jupiter.profile.co.at (8.12.10/8.12.10) with ESMTP id i7RBGsBk018345; Fri, 27 Aug 2004 13:16:54 +0200 Subject: Re: template-id does not match any template declaration From: Arno Wilhelm Reply-To: arno.wilhelm@profile.co.at To: learning c++ Cc: gcc-help@gcc.gnu.org In-Reply-To: References: Content-Type: text/plain Organization: proFILE Computersysteme GmbH Message-Id: <1093605413.24261.1.camel@dione.profile.co.at> Mime-Version: 1.0 Date: Fri, 27 Aug 2004 12:11:00 -0000 Content-Transfer-Encoding: 7bit X-SW-Source: 2004-08/txt/msg00252.txt.bz2 > I am a novice for C++, and I compiled a program with C++ and there are an > error, Pleaes help me. Try this: 1 #include 2 3 4 template 5 class pair 6 { 7 public: 8 pair(T first, T second) {value1=first; value2=second;} 9 T module () {return 0;} 10 11 private: 12 T value1; 13 T value2; 14 }; 16 17 template <> 18 class pair 19 { 20 public: 21 pair (int first, int second) {value1=first; value2=second;} 22 int module ( ) { return (value1 % value2); } 23 private: 24 int value1; 25 int value2; 26 }; 35 36 int main (void) 37 { 38 pair myints (100, 75); 39 pair myfloats (100.0, 75.0); 40 41 std::cout << myints.module() << '\n'; 42 std::cout << myfloats.module() << '\n'; 43 44 return 0; 45 } 46 Arno > Thanks, > > #include > > template > class pair { > T value1, value2; > public: > pair (T first, T second) > {value1=first; value2=second;} > T module () {return 0;} > }; > > template <> > class pair { > int value1, value2; > public: > pair (int first, int second) > {value1=first; value2=second;} > int module (); > }; > > template <> > int pair::module() { > return value1%value2; > } > int main () { > pair myints (100,75); > pair myfloats (100.0,75.0); > std::cout << myints.module() << '\n'; > std::cout << myfloats.module() << '\n'; > return 0; > } > > Error: > templatemodule1.cpp:22: error: template-id `module<>' for `int > pair::module()' does not match any template declaration > templatemodule1.cpp:22: error: syntax error before `{' token > > _________________________________________________________________ > Add photos to your messages with MSN 8. Get 2 months FREE*. > http://join.msn.com/?page=features/featuredemail -- Arno Wilhelm proFILE Computersysteme GmbH