J
Josefo
Hello all. I am a newbie following the C++ tutorial in :
http://www.cplusplus.com/doc/tutorial/templates.html
I am unable to succesfully compile any of the examples with templates
of this tutorial. I use the standard c++ compiler which comes with
ubuntu breezy distro. I guess that somethig is wrong with it or (more
likely..) I should use some option when compiling. This is, for
instance, one of the codes:
// template specialization
#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 (T 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;
}
and these are the error messages (sorry, some of them are in spanish..)
templates3.c:17: error: expected `)' before 'arg'
templates3.c:22: error: el id de plantilla 'uppercase<>' para
'char container<char>::uppercase()' no coincide con ninguna
declaración de plantilla
templates3.c:22: error: declaración inválida de función
templates3.c: In function 'int main()':
templates3.c:31: error: no se encuentra una función coincidente para
la llamada a 'container<char>::container(char)'
templates3.c:14: nota: los candidatos son: container<char>::container()
templates3.c:14: nota:
container<char>::container(const container<char>&)
Can anyone tell me what is going on. Thanks in advance.
http://www.cplusplus.com/doc/tutorial/templates.html
I am unable to succesfully compile any of the examples with templates
of this tutorial. I use the standard c++ compiler which comes with
ubuntu breezy distro. I guess that somethig is wrong with it or (more
likely..) I should use some option when compiling. This is, for
instance, one of the codes:
// template specialization
#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 (T 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;
}
and these are the error messages (sorry, some of them are in spanish..)
templates3.c:17: error: expected `)' before 'arg'
templates3.c:22: error: el id de plantilla 'uppercase<>' para
'char container<char>::uppercase()' no coincide con ninguna
declaración de plantilla
templates3.c:22: error: declaración inválida de función
templates3.c: In function 'int main()':
templates3.c:31: error: no se encuentra una función coincidente para
la llamada a 'container<char>::container(char)'
templates3.c:14: nota: los candidatos son: container<char>::container()
templates3.c:14: nota:
container<char>::container(const container<char>&)
Can anyone tell me what is going on. Thanks in advance.