Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: C++  |  size: 0.93 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. class A {
  5.     public:
  6.     virtual void saraza() = 0;
  7. };
  8.  
  9. class B: public A {
  10.     public:
  11.     virtual void saraza() {
  12.         printf("saraza");
  13.     }
  14. };
  15.  
  16. class C {
  17.     public:
  18.     void trulala(A unDato) {
  19.         a.saraza();
  20.     }
  21. };
  22.  
  23. int main() {
  24.     B b();
  25.     C c();
  26.  
  27.     c.trulala(b);
  28.     return 0;
  29. }
  30.  
  31. /*
  32. barbazul@barbazul ~/Organizacion de Datos/tpDatos/lib/File $ g++ test.cpp -o test
  33. test.cpp:18:20: error: cannot declare parameter ‘unDato’ to be of abstract type ‘A’
  34. test.cpp:4:7: note:   because the following virtual functions are pure within ‘A’:
  35. test.cpp:6:18: note:    virtual void A::saraza()
  36. test.cpp: In member function ‘void C::trulala(A)’:
  37. test.cpp:19:9: error: ‘a’ was not declared in this scope
  38. test.cpp: In function ‘int main()’:
  39. test.cpp:27:7: error: request for member ‘trulala’ in ‘c’, which is of non-class type ‘C()’
  40. */