diff --git a/1541_kmk324.cpp b/1541_kmk324.cpp new file mode 100644 index 0000000..107a510 --- /dev/null +++ b/1541_kmk324.cpp @@ -0,0 +1,47 @@ +#include "Derived.h" +#include "Base.h" +#include +using namespace std; + +int main() +{ + cout << "[upcasting Example]" << endl << endl; + Base* basePtr = new Base(10, 20); + Derived* derPtr = new Derived(30, 50); + + basePtr->printSum(); + derPtr->printSum(); + + basePtr = derPtr; + cout << endl << "after upcasting / Derived -> Base.." << endl; + basePtr->printSum(); + derPtr->printSum(); + ///////////////////////////////////////////////////////////// + + cout << endl << "[Downcasting Example1] " << endl << endl; + Base* basePtr2 = new Derived(10, 20); + Derived* derPtr2 = new Derived(30, 50); + + basePtr2->printSum(); + derPtr2->printSum(); + + derPtr2 = static_cast(basePtr2); //¿Ü¿ì±â + cout << endl << "after downcasting / Base -> Derived.." << endl; + + basePtr2->printSum(); + derPtr2->printSum(); + + + cout << endl << "[Downcasting Example2]" << endl << endl; + Base* basePtr3 = new Base(10, 20); + Derived* derPtr3 = new Derived(30, 50); + + cout << endl << "After downcasting Base->Derived...." << endl; + derPtr3 =/*static_cast*/(Derived*)(basePtr3); // ??? + basePtr3->printSum(); + derPtr3->printSum(); + + system("pause"); + + return 0; +} \ No newline at end of file diff --git a/README.md b/README.md index cd76060..dd824f6 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,6 @@ - kmk324 - 1530 - tip 쉬움. + - 1541 + - tip \ No newline at end of file