In a nutshell, I am trying to access a private data member of a class, which is in a class (yes, a class in a class)
I want Phonebook::display() to show Phonebook.addr.house
I get an error telling me I can't access it because it's private. So... do I have to put that display() function inside Address?
Code:#include <iostream> #include <cstdlib> class Address { private: unsigned int house; unsigned int street; public: Address(unsigned int h = 0, unsigned int s = 0) {house = h; street = s;} }; class Phonebook { private: unsigned int fax; unsigned int phone; Address addr; public: Phonebook(unsigned int f = 0, unsigned int p = 0, Address a = 0) {fax = f; phone = p; addr = a;} void display(); }; void Phonebook::display() { std::cout << addr.house; } int main() { Phonebook brian(5821945, 5827052, (8724, 87)); brian.display(); system("pause"); return 0; }



LinkBack URL
About LinkBacks


