-
-
Save jitpaul/e3dd6303b86fbb86b6c75f16782b4da5 to your computer and use it in GitHub Desktop.
TypeCasting
This file contains 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> | |
using namespace std; | |
class Base_Class { | |
public: | |
virtual void func() {} | |
}; | |
class Derived_Class :public Base_Class { | |
public: | |
void func() {} | |
}; | |
int main() { | |
Base_Class * a = new Base_Class(); | |
Derived_Class *b = static_cast<Derived_Class*>(a); | |
if (!b) cout << "b is nullptr"; | |
else cout << "b is not nullptr"; | |
cin.get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment