Skip to content

Instantly share code, notes, and snippets.

@Noobgam
Last active August 17, 2018 08:50
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 Noobgam/64ac15d1af52321b043deba97ea4688e to your computer and use it in GitHub Desktop.
Save Noobgam/64ac15d1af52321b043deba97ea4688e to your computer and use it in GitHub Desktop.
//a.cpp
//a.* can not include b.*
struct Test {
int Bar();
};
struct Test2 {
int Barr();
};
template <class T>
int Foo(T& t) {
return -1;
};
template <>
int Foo<Test>(Test& t) {
return t.Bar();
}
template <>
int Foo<Test2>(Test2& t) {
return t.Barr();
}
//b.cpp
#include "a.cpp"
#include <iostream>
using namespace std;
struct Test {
int Bar() { return 1; }
};
struct Test2 {
int Barr() { return 2; }
};
int main() {
Test a;
Test2 b;
cout << Foo(a) << " " << Foo(b) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment