(Note this is not the final post, there will be more implementation later.)
Think following scenario: We are trying to track our money. So we create a class for it.
#include <string> #include <iostream>
class Money { public : std :: string currency ; int amount ; } ;
int main ( ) { Money inBank ; inBank . currency = "dollar" ; inBank . amount = 10 ;
std :: cout << "Total money I have: " << inBank . amount << " " << inBank . currency << std :: endl ;
return 0 ; }
// Total money I have: 10 dollar
Enter fullscreen mode
Exit fullscreen mode
It looks a bit hard to print total money. It could be so great if we could just write std::cout << inBank << std::endl . Let's try that first.
#include <string> #include <iostream>
class Money { public : std :: string currency ; int amount ; } ;
int main ( ) { Money inBank ; inBank . currency = "dollar" ; inBank .…