Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Last active April 26, 2018 20:37
Show Gist options
  • Save jitpaul/e46e2e293d8f31ef5191853e1cd1affd to your computer and use it in GitHub Desktop.
Save jitpaul/e46e2e293d8f31ef5191853e1cd1affd to your computer and use it in GitHub Desktop.
TypeCasting
#include <iostream>
#include <string>
using namespace std;
struct A{
int first;
int second;
A(int first, int second):first(first), second(second){}
};
struct B{
string third;
string fourth;
};
int main() {
A* a = new A(1,2);
B* b = (B*)a;
cout<<b->third; //Run-time error
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment