Skip to content

Instantly share code, notes, and snippets.

@DineshDevaraj
Last active April 20, 2017 05:47
Show Gist options
  • Save DineshDevaraj/193da370ddb8def6b4bbc6a6f1d37d48 to your computer and use it in GitHub Desktop.
Save DineshDevaraj/193da370ddb8def6b4bbc6a6f1d37d48 to your computer and use it in GitHub Desktop.
struct Manager;
struct Employee
{
Manager * promote_to_manager();
};
struct Manager : Employee
{
Manager() {}
/* converting constructor */
Manager(const Employee &employee)
{
*(Employee *)this = employee;
}
};
Manager * Employee::promote_to_manager()
{
Employee *manager = new Manager;
*manager = *this;
delete this;
return (Manager *)manager;
}
int main()
{
Employee *employee = new Employee;
Manager *manager = employee->promote_to_manager();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment