Created
May 10, 2015 09:31
-
-
Save beyondwdq/aa635e8ad7dafa114f99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class Base | |
{ | |
public: | |
Base(const string &firstname, const string &lastname) | |
: firstname_(firstname) | |
, lastname_(lastname) | |
, fullname_(firstname_ + ", " + lastname_) | |
{ | |
hello(); | |
} | |
virtual void hello() | |
{ | |
cout << "Hello! I'm " << fullname() << endl; | |
} | |
const string & fullname() { return fullname_; } | |
private: | |
string fullname_; | |
string firstname_; | |
string lastname_; | |
}; | |
class Derived : public Base | |
{ | |
public: | |
Derived(const string &firstname, const string &lastname) | |
: Base(firstname, lastname) | |
{ | |
} | |
virtual void hello() | |
{ | |
cout << "Aloha! My name is " << fullname() << endl; | |
} | |
}; | |
int main(int argc, const char *argv[]) | |
{ | |
// Expected output: "Aloha! My name is Harry, Potter". | |
// Any issue? | |
Derived p("Harry", "Potter"); | |
// Any problem with this array definition? | |
Derived plist[5]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment