public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "learning c++" <learning_c@hotmail.com>
To: gcc-help@gcc.gnu.org
Subject: String and Char in function template
Date: Tue, 31 Aug 2004 22:06:00 -0000	[thread overview]
Message-ID: <BAY12-F68r6beUzmRf60003aea9@hotmail.com> (raw)

Hi, Everyone:

I have a short code about function template like this:

#include <iostream>
#include <string>
using std::cout;

template <typename T> // 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<class _Tp> struct std::greater' is not a function,
greater.cpp:7: error:   conflict with `template<class T> 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

                 reply	other threads:[~2004-08-31 20:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY12-F68r6beUzmRf60003aea9@hotmail.com \
    --to=learning_c@hotmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).