473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

template id does not match any template declaration?

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.
Feb 21 '06 #1
2 9753
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
Feb 21 '06 #2
On Tue, 21 Feb 2006 13:15:25 -0500 Victor Bazarov
<v.********@comAcast.net> 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.
Feb 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rennie deGraaf | last post by:
The attached code compiles and works properly when I comment out the declaration, definition, and invocations of the method 'eck'. With "eck" in there, g++ fails with ttest.cpp:23: template-id...
3
by: Adam | last post by:
I'm trying to write a template specialization, and the char* specialization is giving me some trouble. Here's a simplified example: /**************************/ /* test.cpp */ #include...
6
by: blueblueblue2005 | last post by:
Hi, below is the code I copy from c++ tutorial, it is about template specialization, but when I compile, I got error message: error: template-id `module<>' for `int mypair<int>::module()' does...
6
by: Kaba | last post by:
Here is a short snippet of code that does not compile (tested with Vc8 and Comeau). This is because somehow Vector<0gets instantiated, for which the array size goes to 0. However, I don't quite get...
7
by: Noah Roberts | last post by:
template < typename V > class Outer { public: template < typename T > class Inner { private: template <classfriend class Inner; };
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
2
by: Joseph Turian | last post by:
I have a class Feature defined, which is a kind of Vocab: template <class T, unsigned I> class Vocab : boost::totally_ordered<Vocab<T,I { public: Vocab(); Vocab(const T& t); template<typename...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
3
by: Pallav singh | last post by:
Hi All , i writing a shared library ,containing code in template i trying to explicitly instantiate functional & class template ........But i am getting Error #include<iostream> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.