B
blueblueblue2005
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
not match any template declaration
tmp.cpp:28: error: syntax error before `{' token
I guess it might be that my compiler does not recognize this type of
using template??? I am using g++-3.3 compiler under Ubuntu linux. any
help will be appreciated
here is the code :
1 //Template specialization
2 #include <iostream>
3
4 using namespace std;
5
6 template <class T>
7 class mypair {
8 T value1, value2;
9 public:
10 mypair (T first, T second)
11 {value1=first; value2=second;}
12 T module () {return 0;}
13 };
14
15 template <>
16 class mypair <int> {
17 int value1, value2;
18 public:
19 mypair (int first, int second)
20 {
21 value1=first;
22 value2=second;
23 }
24 int module ();
25 };
26
27 template <>
28 int mypair<int>::module() {
29 return value1%value2;
30 }
31
32 int main () {
33 mypair <int> myints (100,75);
34 mypair <float> myfloats (100.0,75.0);
35 cout << myints.module() << '\n';
36 cout << myfloats.module() << '\n';
37 return 0;
38 }
specialization, but when I compile, I got error message:
error: template-id `module<>' for `int mypair<int>::module()' does
not match any template declaration
tmp.cpp:28: error: syntax error before `{' token
I guess it might be that my compiler does not recognize this type of
using template??? I am using g++-3.3 compiler under Ubuntu linux. any
help will be appreciated
here is the code :
1 //Template specialization
2 #include <iostream>
3
4 using namespace std;
5
6 template <class T>
7 class mypair {
8 T value1, value2;
9 public:
10 mypair (T first, T second)
11 {value1=first; value2=second;}
12 T module () {return 0;}
13 };
14
15 template <>
16 class mypair <int> {
17 int value1, value2;
18 public:
19 mypair (int first, int second)
20 {
21 value1=first;
22 value2=second;
23 }
24 int module ();
25 };
26
27 template <>
28 int mypair<int>::module() {
29 return value1%value2;
30 }
31
32 int main () {
33 mypair <int> myints (100,75);
34 mypair <float> myfloats (100.0,75.0);
35 cout << myints.module() << '\n';
36 cout << myfloats.module() << '\n';
37 return 0;
38 }