From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15288 invoked by alias); 31 Aug 2004 20:35:37 -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 15263 invoked from network); 31 Aug 2004 20:35:36 -0000 Received: from unknown (HELO hotmail.com) (64.4.35.6) by sourceware.org with SMTP; 31 Aug 2004 20:35:36 -0000 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 31 Aug 2004 13:35:35 -0700 Received: from 130.233.19.1 by by12fd.bay12.hotmail.msn.com with HTTP; Tue, 31 Aug 2004 20:35:34 GMT X-Originating-IP: [130.233.19.1] X-Originating-Email: [learning_c@hotmail.com] X-Sender: learning_c@hotmail.com From: "learning c++" To: gcc-help@gcc.gnu.org Bcc: Subject: String and Char in function template Date: Tue, 31 Aug 2004 22:06:00 -0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 31 Aug 2004 20:35:35.0329 (UTC) FILETIME=[116CB910:01C48F9A] X-SW-Source: 2004-08/txt/msg00305.txt.bz2 Hi, Everyone: I have a short code about function template like this: #include #include using std::cout; template // template parameter list T const &greater(T const &first, T const &second) { return (first > second) ? first : second; } int main() { int a = 1, b = 2; cout << greater(a, b) << '\n'; long c = 4L, d = 3L; cout << greater(c, d) << '\n'; double e = 5.62, f = 3.48; cout << greater(e, f) << '\n'; char g = 'A', h = 'a'; cout << greater(g, h) << '\n'; std::string two("two"), three("three"); cout << greater(two, three) << '\n'; char const *two("two"), *three("three"); cout << greater(two, three) << '\n'; char const *two("two"), *three("three"); cout << greater(two, three) << '\n'; return 0; } when I compile it, the errors are the following: /v/dunix51_alpha/gnu/gcc/lib/gcc-lib/alphaev5-dec-osf5/3.3/include/c++/bits/stl_function.h: In function `int main()': /v/dunix51_alpha/gnu/gcc/lib/gcc-lib/alphaev5-dec-osf5/3.3/include/c++/bits/stl_function.h:188: error: ` template struct std::greater' is not a function, greater.cpp:7: error: conflict with `template const T& greater(const T&, const T&)' greater.cpp:22: error: in call to `greater' greater.cpp:23: error: conflicting types for `const char*two' greater.cpp:21: error: previous declaration as `std::string two' greater.cpp:23: error: conflicting types for `const char*three' greater.cpp:21: error: previous declaration as `std::string three' greater.cpp:23: warning: statement with no effect greater.cpp:23: confused by earlier errors, bailing out What is wrong with my code? In addition, I hope to know something about "const" in "char const *two("two"), *three("three");" and the difference between "using std::cout;" and "using namespace std;" Thanks in advance! _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail