Created
August 30, 2017 09:28
-
-
Save mcleary/12e2147494aa2f26c6f53dc5c3db351a to your computer and use it in GitHub Desktop.
Full template specialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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