Skip to content

Instantly share code, notes, and snippets.

@bugaevc
Last active May 1, 2016 20:34
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 bugaevc/e2fc865c83700583c92ea9afc9e82362 to your computer and use it in GitHub Desktop.
Save bugaevc/e2fc865c83700583c92ea9afc9e82362 to your computer and use it in GitHub Desktop.
struct A {
int x;
};
struct B: A {
int y;
};
struct C: B {
int z;
};
B func(B arg)
{
return arg;
}
int main() {
A a;
B b;
/* this works fine:
* a B value is a valid A value
* to put it another way, you can use a B value
* whenever an A value is expected
*/
a = b;
/* on the other hand,
* this would be an error:
*/
// b = a;
// this works just fine
C arg;
A res = func(arg);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment