Skip to content

Instantly share code, notes, and snippets.

@PIlin
Created July 5, 2016 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PIlin/91d057f8ec1a675fa558174fa4fa1cf0 to your computer and use it in GitHub Desktop.
Save PIlin/91d057f8ec1a675fa558174fa4fa1cf0 to your computer and use it in GitHub Desktop.
#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