Skip to content

Instantly share code, notes, and snippets.

@mcleary
Created August 30, 2017 09:28
Show Gist options
  • Save mcleary/12e2147494aa2f26c6f53dc5c3db351a to your computer and use it in GitHub Desktop.
Save mcleary/12e2147494aa2f26c6f53dc5c3db351a to your computer and use it in GitHub Desktop.
Full template specialization
#include <iostream>
class Statement
{
public:
template<typename T>
T Get(int index);
template<>
int Get(int index)
{
return 42;
}
template<>
float Get(int index)
{
return 42.0f;
}
template<>
double Get(int index)
{
return 42.0;
}
private:
};
int main()
{
Statement stmt;
std::cout << "Get int: " << stmt.Get<int>(0) << std::endl;
std::cout << "Get float: " << stmt.Get<float>(0) << std::endl;
std::cout << "Get double: " << stmt.Get<double>(0) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment