mardi 21 juillet 2015

SFINAE did not compile [duplicate]

This question already has an answer here:

Very often I used SFINAE before but I have a very very simple example I can't get to run today.

class X
{
    public:
        template <typename CHECK, typename = typename std::enable_if< std::is_floating_point<CHECK>::value, void>::type >
            void Do()
            {
                std::cout << "yes" << std::endl;
            }

        template <typename CHECK, typename = typename std::enable_if< !std::is_floating_point<CHECK>::value, void>::type>
            void Do()
            {
                std::cout<< "no" << std::endl;
            }

};

int main()
{
    X x;
    x.Do<float>();
}

Error:

src/main.cpp:20:18: error: 'template void X::Do()' cannot be overloaded

src/main.cpp:14:18: error: with 'template void X::Do()' void Do()

I want to disable any overload with enable_if but it doesn't work...

Any idea what today I did wrong?

Aucun commentaire:

Enregistrer un commentaire