This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: template-id does not match any template declaration
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: learning c++ <learning_c at hotmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Fri, 27 Aug 2004 07:26:53 -0500
- Subject: Re: template-id does not match any template declaration
- References: <BAY12-F21fgzBscdTfM00004a6c@hotmail.com>
Hi,
You were almost there! Just a little syntax tweak for your separate
definition of your member function of your explicit template specialization
for pair<int>::module. (See below.)
Also, I changed the return statement on your general pair template
pair::module to something more suitable.
Caution, there is a std::pair. Your ::pair is okay, but could be a little
better protected by putting your pair class in your own namespace. Or,
make sure you never do a "using namespace std" anywhere (I disparage
"pulling in the std uberverse namespace" on general principle).
HTH,
--Eljay
-------------------------------
#include <iostream>
using std::cout;
template <class T>
class pair
{
T value1;
T value2;
public:
pair(T first, T second)
{
value1 = first;
value2 = second;
}
T module()
{
return T();
}
};
template <>
class pair<int>
{
int value1;
int value2;
public:
pair(int first, int second)
{
value1 = first;
value2 = second;
}
int module();
};
int pair<int>::module()
{
return value1 % value2;
}
int main()
{
pair<int> myints(100, 75);
pair<float> myfloats(100.0, 75.0);
cout << myints.module() << '\n';
cout << myfloats.module() << '\n';
}