Created
July 5, 2016 16:04
-
-
Save PIlin/91d057f8ec1a675fa558174fa4fa1cf0 to your computer and use it in GitHub Desktop.
This file contains 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> | |
template <typename T> | |
void func(T& t) | |
{ | |
t.method(); | |
} | |
struct A { void method() { std::cout <<"a"; } }; | |
struct B { int justSomeValue; }; | |
void func(B& b) { std::cout << b.justSomeValue; } | |
void func(int& i) { std::cout << i; } | |
void func(float& f) { std::cout << f; } | |
struct SFail {}; | |
int main() | |
{ | |
A a; | |
func(a); // ok | |
B b; | |
func(b); // ok | |
int i = 42; | |
func(i); // ok | |
float f = 42.0f; | |
func(f); // ok | |
SFail sfail; | |
func(sfail); // fail | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment