I have this hw problem, but I can't figure out what the problem is. If I run this code I get an assertion error. Also if i run without commenting out the return outStream line, it won't compile saying I'm converting an istream to ostream. Any clues?

#include <iostream>
#include <string>

using namespace std;

class Person
{
protected:
	string name;

public:
	Person():name('\0'){cout << "Default Person Constructor" << endl;}
	Person(string theName):name(theName){cout << "Parameterized Person Constructor" << endl;}
	Person(const Person& theObject);
	string getName() const{return name;}
	Person& operator=(const Person& rtSide)
	{
		string Name;
		Name = rtSide.name;
		return Person(Name);
	}
	friend istream& operator >>(istream& inStream, Person& personObject)
	{
		inStream >> personObject.name;
		return inStream;
	}
	friend istream& operator <<(ostream& outStream, const Person& personObject)
	{
		outStream << "Person's name: " << personObject.name << endl;
		/*return outStream;*/
	}
};

class Doctor
{
protected:
	string specialty;
	double fee;

public:
	Doctor():specialty('\0'), fee(0){cout << "Default Doctor Constructor" << endl;}
	Doctor(string Specialty):specialty(Specialty), fee(0){ cout << "Specialty Doctor Constructor" << endl;}
	Doctor(double Fee):specialty('\0'), fee(Fee){cout << "Fee Doctor Constructor" << endl;}
	Doctor(string Specialty, double Fee):specialty(Specialty), fee(Fee){cout << "Parameterized Doctor Constructor" << endl;}
	string getSpecialty() const{return specialty;}
	double getFee() const{return fee;}
	const Doctor& operator=(const Doctor& rtSide)
	{
		string Specialty;
		double Fee;
		Specialty = rtSide.specialty;
		Fee = rtSide.fee;
		return Doctor(Specialty, Fee);
	}
	Doctor(const Doctor& theObject);
};

class Patient: public Person
{
//protected:
//	Doctor phys;

public:
	Patient(): Person(){};
};

int main()
{
	Person x;

	system("Pause");
	return 0;
}

Hi,

Couple of things gone wrong in your program, I am just fixing the Person class and pointing out some issues, see the inline comments:

//Now it should compile, fix your other class like this
class Person
{
protected:
	string name;

public:
	Person():name(""){cout << "Default Person Constructor" << endl;}  // You can not do Person():name('\0'), '\0' is a charecter and string type //variable can not be initialized by a character
	Person(string theName):name(theName){cout << "Parameterized Person Constructor" << endl;}
	Person(const Person& theObject);
	string getName() const{return name;}
	Person& operator=(const Person& rtSide)
	{
		name = rtSide.name;
		return *this;
	}
	friend istream& operator >>(istream& inStream, Person& personObject)
	{
		inStream >> personObject.name;
		return inStream;
	}
	friend ostream& operator <<(ostream& outStream, const Person& personObject) //You are returning outStream and it is a ostream type object so why is the return type you set istream
	{
		outStream << "Person's name: " << personObject.name << endl;
		return outStream;
	}
};

Following link will show you all the string class constructors you can use:
http://www.cplusplus.com/reference/string/string/string/

wow thanks, took me a min to even find what changed for the outstream problem!

Next time, post the error message. It is helpful sometimes even without reading a code to spot error!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.