template id does not match any template declaration?

Discussion in 'C++' started by Alex Buell, Feb 21, 2006.

  1. Alex Buell

    Alex Buell Guest

    This is what I'm trying to compile with GCC 3.4.4 under Linux. The
    error I'm getting is:

    g++ -s -O3 -Wall class2.cc -o class2
    class2.cc:25: error: template-id `uppercase<>' for `char
    container<char>::uppercase()' does not match any template declaration
    class2.cc:25: error: invalid function declaration make: *** [class2]
    Error 1

    What's wrong with it? The code is as below. Thanks for any hints
    offered.

    #include <iostream>

    using namespace std;

    template<class T>
    class container
    {
    T element;
    public:
    container (T arg) { element = arg; }
    T increase () { return ++element; }
    };

    template<>
    class container<char>
    {
    char element;
    public:
    container (char arg) { element = arg; }
    char uppercase();
    };

    template<>
    char container<char>::uppercase()
    {
    if ((element >= 'a') && (element <= 'z'))
    element += 'A' - 'a';

    return element;
    }

    int main()
    {
    container<int> myint(7);
    container<char> mychar('j');

    cout << myint.increase() << endl;
    cout << mychar.uppercase() << endl;

    return 0;
    }


    --
    http://www.munted.org.uk

    "Honestly, what can I possibly say to get you into my bed?" - Anon.
    Alex Buell, Feb 21, 2006
    #1
    1. Advertising

  2. Alex Buell wrote:
    > This is what I'm trying to compile with GCC 3.4.4 under Linux. The
    > error I'm getting is:
    >
    > g++ -s -O3 -Wall class2.cc -o class2
    > class2.cc:25: error: template-id `uppercase<>' for `char
    > container<char>::uppercase()' does not match any template declaration
    > class2.cc:25: error: invalid function declaration make: *** [class2]
    > Error 1
    >
    > What's wrong with it? The code is as below. Thanks for any hints
    > offered.
    >
    > #include <iostream>
    >
    > using namespace std;
    >
    > template<class T>
    > class container
    > {
    > T element;
    > public:
    > container (T arg) { element = arg; }
    > T increase () { return ++element; }
    > };
    >
    > template<>
    > class container<char>
    > {
    > char element;
    > public:
    > container (char arg) { element = arg; }
    > char uppercase();
    > };
    >
    > template<>


    Drop the line above. What you're doing here is _definining_, not
    _specialising_. You've already specialised it. Now, 'template<>' is
    extraneous.

    > char container<char>::uppercase()
    > {
    > if ((element >= 'a') && (element <= 'z'))
    > element += 'A' - 'a';
    >
    > return element;
    > }
    >
    > int main()
    > {
    > container<int> myint(7);
    > container<char> mychar('j');
    >
    > cout << myint.increase() << endl;
    > cout << mychar.uppercase() << endl;
    >
    > return 0;
    > }
    >
    >


    V
    --
    Please remove capital As from my address when replying by mail
    Victor Bazarov, Feb 21, 2006
    #2
    1. Advertising

  3. Alex Buell

    Alex Buell Guest

    On Tue, 21 Feb 2006 13:15:25 -0500 Victor Bazarov
    <> waved a wand and this message magically
    appeared:


    > > template<>
    > > class container<char>
    > > {
    > > char element;
    > > public:
    > > container (char arg) { element = arg; }
    > > char uppercase();
    > > };
    > >
    > > template<>

    >
    > Drop the line above. What you're doing here is _definining_, not
    > _specialising_. You've already specialised it. Now, 'template<>' is
    > extraneous.


    Thank you, that did the trick. I haven't coded C++ for a very long time
    and I'm trying to get back into it, with all those new and wonderful
    features that's been added since the early 1990s.

    Cheers,
    Alex
    --
    http://www.munted.org.uk

    "Honestly, what can I possibly say to get you into my bed?" - Anon.
    Alex Buell, Feb 21, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    947
  2. kelvSYC
    Replies:
    6
    Views:
    7,213
    Richard Herring
    May 17, 2005
  3. blueblueblue2005
    Replies:
    6
    Views:
    996
    blueblueblue2005
    Jul 19, 2005
  4. Joseph Turian
    Replies:
    2
    Views:
    839
    Joseph Turian
    Mar 22, 2007
  5. Klaus
    Replies:
    3
    Views:
    1,041
    Klaus
    Mar 31, 2008
Loading...

Share This Page