Last active
June 8, 2018 07:48
-
-
Save vpetrigo/bc4493af53dd80ba5a66a54e3322a326 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> | |
struct Base { | |
}; | |
struct D1 : Base { | |
}; | |
struct D2 : Base { | |
int a{10}; | |
}; | |
struct D3 : D1, D2 { | |
}; | |
// base указывает на экземпляр Base, соответствующий D1 | |
// нужно вернуть указатель на экземпляр Base, соответсвующий D2 | |
Base * D1BaseToD2Base( Base const * base ) | |
{ | |
/* YOUR IMPLEMENTATION HERE*/ | |
} | |
int main() { | |
D3 d3; | |
Base *ptr = static_cast<D1 *> (&d3); | |
Base *ptra = NULL; | |
ptra = D1BaseToD2Base(ptr); | |
std::cout << static_cast<D2 *>(ptra)->a << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line
std::cout << static_cast<D2 *>(ptra)->a << std::endl;
should be replaced withstd::cout << static_cast<D2 const*>(ptra)->a << std::endl;
, otherwise it won't be compiled