// this uses code by michael dawson

#include <string>
#include <iostream>

using std::cout;
using std::string;
using std::ostream;

// class declaration
class Critter
{
	// the following are global functions that are friends of this class
	friend void Peek(const Critter& aCritter);
	friend ostream& operator<<(ostream& os, const Critter& aCritter);
	
public:
	Critter(const string& name = ""): m_Name(name){}
	
private:
	string m_Name;
};

// friend function definiton
void Peek(const Critter& aCritter);
ostream& operator<<(ostream& os, const Critter& aCritter);

// porgram starts here
int main()
{
	Critter crit("Goblin");

	cout << "Calling Peek() to access critter class private data, m_Name: ";
	Peek(crit);

	cout << "\nSending crit object to cout with the << operator: ";
	cout << crit;
	
	return 0;
}

// global friend function which can access all of a Critter 
// object's member data
void Peek(const Critter& aCritter)
{
	cout << aCritter.m_Name << std::endl;
}

// global friend function that overloads the << operator
// so we can send a criter object to cout
ostream& operator<<(ostream& os, const Critter& aCritter)
{
	os << "\nCritter Object - ";
	os << "m_Name: " << aCritter.m_Name << std::endl;

	return os;
}


