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
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();
And, also I have this class:
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);
};
I did this in main, and it displayed correctly, so I assumed if I do the same thing in People, it should work.
Code:
MyString s2("Hello");
s2.showit();
Well, when I called this:
Code:
cout << "People::adam.show()" << endl;
adam.show();
there were blank lines only. Why is that?
The inline implementation of the methods is as such:
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;
}
The age gets displayed (of course), but the rest is just blank lines... Can anybody help me with this?