Skip to content

Instantly share code, notes, and snippets.

@beyondwdq
Created May 10, 2015 09:31
Show Gist options
  • Save beyondwdq/aa635e8ad7dafa114f99 to your computer and use it in GitHub Desktop.
Save beyondwdq/aa635e8ad7dafa114f99 to your computer and use it in GitHub Desktop.
#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