compare overloading operator<< as a class member and as a non-member


👍 g++ -std=c++11 member_or_not.cpp
👍 ./a.out
Felix 13
Felix 13
👍 cat member_or_not.cpp 
#include <iostream>
using namespace std;

struct Kid {
  string name;
  int age;
  ostream& operator<<(ostream &o) {
    o << name << ' ' << age;
    return o;
  }
};

ostream& operator<<(ostream &o, 
                    const Kid &k) {
  o << k.name << ' ' << k.age;
  return o;
}

int main() {
  Kid k{"Felix", 13};
  k << cout << endl;
  cout << k << endl;
}