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

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.79 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. c   Initializer list
  2. class A {
  3. public:
  4.   A(String sender, String receiver, String service) {
  5.                                                         //do something here
  6.                                                     }
  7. }
  8.  
  9. class B {
  10. public:
  11.   B(String sender, String receiver, String service) {
  12.                                                         //do something here
  13.                                                     }
  14. }
  15.        
  16. A::A(sender,receiver, service) : B(sender,receiver, service) {
  17. //do something here
  18. }
  19.        
  20. class B
  21. {
  22.    int _x;
  23. public:
  24.    B();
  25.    B(int x);
  26. }
  27.  
  28. B::B()
  29. {
  30.    _x = 42;
  31. }
  32. B::B(int x)
  33. {
  34.    _x = x;
  35. }
  36.  
  37. class A : public B
  38. {
  39. public:
  40.     A(int x);
  41. };
  42.  
  43. A::A(int x) : B(x) {}
  44.        
  45. A::A(int x) : B(x) {}
  46. //...
  47. A a(10);
  48. //a._x will be 10
  49.        
  50. A::A(int x) {}
  51.        
  52. A a(10);
  53. //a._x will be 42