Hi, all. I was working on this and I thought I finally figured it out but when I ran this program what it did is to output blank lines. This is confusing...
OK, so I got a class called MyString which is as follows
And, also I have this class:Code:class MyString { private: int len; char * str; static int counter; public: MyString(); MyString(char* nts_string); MyString(const char * string_n); MyString(const MyString& s); static int numStrings(void); ~MyString(); friend ostream& operator<<(ostream& os, const MyString &s); void showit();
I did this in main, and it displayed correctly, so I assumed if I do the same thing in People, it should work.Code:class People { private: int age; MyString name; MyString address; public: People(); People(char* nts_string1, int n, char* nts_string2); People(int n); friend ostream& operator<<(ostream& os, const People &s); MyString getName() const; MyString getAddress() const; void show(void); };
Well, when I called this:Code:MyString s2("Hello"); s2.showit();
there were blank lines only. Why is that?Code:cout << "People::adam.show()" << endl; adam.show();
The inline implementation of the methods is as such:
The age gets displayed (of course), but the rest is just blank lines... Can anybody help me with this?Code:MyString getName() const { return name; } MyString getAddress() const { return address; } void show(void) { // print data including the cars owned cout << age << "\n"; cout << getName() << "\n"; cout << getAddress() << endl; }



LinkBack URL
About LinkBacks



Want to add some