Last active
April 20, 2017 05:47
-
-
Save DineshDevaraj/193da370ddb8def6b4bbc6a6f1d37d48 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
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