Muzer

C++ contravariance test

May 26th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.23 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. };
  6.  
  7. class B : A
  8. {
  9.   public:
  10.     int magic;
  11. };
  12.  
  13. void evilFunc(A as[])
  14. {
  15.   A a;
  16.   as[0] = a;
  17. }
  18.  
  19. int main(void)
  20. {
  21.   B bs[1];
  22.   evilFunc(bs);
  23.   std::cout << bs[0].magic << std::endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment