Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Last active April 26, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/e3dd6303b86fbb86b6c75f16782b4da5 to your computer and use it in GitHub Desktop.
Save jitpaul/e3dd6303b86fbb86b6c75f16782b4da5 to your computer and use it in GitHub Desktop.
TypeCasting
#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