daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MyClass::MyClass(): _capacity(15), _data(NULL), _len(0)
  2. {
  3. }
  4.    
  5. MyClass::MyClass()
  6. {
  7.   _capacity=15;
  8.   _data=NULL;
  9.   _len=0
  10. }
  11.    
  12. struct aa
  13. {
  14.     int i;
  15.     const int ci;       // constant member
  16.  
  17.     aa() : i(0) {} // will fail, constant member not initialized
  18. };
  19.  
  20. struct aa
  21. {
  22.     int i;
  23.     const int ci;
  24.  
  25.     aa() : i(0) { ci = 3;} // will fail, ci is constant
  26. };
  27.  
  28. struct aa
  29. {
  30.     int i;
  31.     const int ci;
  32.  
  33.     aa() : i(0), ci(3) {} // works
  34. };
  35.    
  36. struct bb {};
  37.  
  38. struct aa
  39. {
  40.     bb& rb;
  41.     aa(bb& b ) : rb(b) {}
  42. };
  43.  
  44. // usage:
  45.  
  46. bb b;
  47. aa a(b);
  48.    
  49. struct bb {};
  50.  
  51. struct dd
  52. {
  53.     char c;
  54.     dd(char x) : c(x) {}
  55. };
  56.  
  57. struct aa : dd
  58. {
  59.     bb& rb;
  60.     aa(bb& b ) : dd('a'), rb(b) {}
  61. };
  62.    
  63. class MyClass {
  64. private:
  65.     const int _capacity;
  66.     const void *_data;
  67.     const int _len;
  68. // ...
  69. };
  70.    
  71. MyClass::MyClass() : _capacity(someMethod()), _data(someOtherMethod()), _len(yetAnotherMethod()) {
  72. }
  73.    
  74. std::string a;
  75. a = "hai";
  76.    
  77. std::string a("hai");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top