Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Last active Apr 26, 2018
Embed
What would you like to do?
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