Re: template-id does not match any template declaration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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';
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux