Objects & Operator Overloading

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void object_1::display(std::ostream &out)
{
	out << left  << setw(28) << "Person"   << setw(20) << "Thing" ;
	out << right << setw(5)  << "Place" << setw(5)  << "Idea" << endl;

	out << left  << setw(28) << "----"   << setw(20) << "--------" ;
	out << right << setw(5)  << "----- " << setw(5)  << "------" << endl;
}

ostream& operator<<(ostream& out, const object_1& obj_1)
{
	obj_1.display(out);
	out << obj_1.chPtrMember1 << obj_1.chPtrMember2 << obj_1.iMember1 << obj_1.iMember2;
	return out;
}


The obj_1.display(out) void function is returning ints; "zero's" where their should be spaces.. Any ideas why?
Last edited on
I'm confused. Is displayHeaders() static? If so, why can you access non-static members? If not, Why is the call static-like?
And your comments don't make sense. Why are you calling an object1 function in an overloaded operator<< that takes an object_2?

Data passed by reference can't go out of scope in a single-threaded program. If you passed a reference to something, that something will be there for the duration of the function unless you do something very stupid like delete &reference (it's stupid because the reference could point to stack data).
I solved it except for a IOMANIP part. I reposted..Sorry I know, confusion post.
Last edited on
Topic archived. No new replies allowed.