Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Last active April 26, 2018 20:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jitpaul/4eb3613a263d9b793ad7206459ff9f61 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 = static_cast<B*>(a); //Compiler Error
cout<<b->third;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment