Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -*- C++ -*-
- #include <string>
- #include <iostream>
- using namespace std;
- struct A {
- int foo() const { return 3; }
- double bar() const { return 3.0; }
- };
- struct B {
- int foo() const { return 10000; }
- string bar() const { return "B is for BAR"; }
- };
- template <typename T>
- void fn(const T& obj) {
- cout << obj.foo() << " " << obj.bar() << endl;
- }
- int main() {
- A a;
- fn(a);
- B b;
- fn(b);
- return 0;
- }
- // Prints:
- //
- // 3 3
- // 10000 B is for BAR
- //
- // (as you'd hope)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement