Skip to content

Instantly share code, notes, and snippets.

@cout
Created July 22, 2014 18:12
Show Gist options
  • Save cout/aa5d6196371f1a429f69 to your computer and use it in GitHub Desktop.
Save cout/aa5d6196371f1a429f69 to your computer and use it in GitHub Desktop.
cannot specialize a member of an unspecialized template
#include <iostream>
template<typename T, typename U>
class Foo
{
public:
template<typename V>
void operator()(V const &)
{
std::cout << "default" << std::endl;
}
};
template<typename T, typename U>
template<>
void
Foo<T, U>::
operator()<int>(int const &)
{
std::cout << "specialized" << std::endl;
}
int main()
{
Foo<int, double> foo;
foo(42);
}
// cout@ubuntu:~/tmp $ clang++ test.cpp -std=c++11
// test.cpp:19:1: error: cannot specialize (with 'template<>') a member of an unspecialized template
// operator()<int>(int const &)
// ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment