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

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 14  |  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. How do I initialize a struct in a Class constructor list? [closed]
  2. class Foo
  3. {
  4. private:
  5.     int x;
  6.     int y;
  7.     int z;
  8.     somestruct p;
  9. public:
  10.     Foo(): x(1), y(2), z(3)
  11.     {
  12.         // other stuff
  13.     }
  14. };
  15.        
  16. struct MyStruct
  17. {
  18.     MyStruct(int i): // Constructor
  19.         myData(i)
  20.     { }
  21.  
  22.     int myData;
  23. };
  24.  
  25. class MyClass
  26. {
  27. public:
  28.     MyClass() :  // default constructor
  29.         m_strct(0)
  30.     { }
  31.  
  32. private:    
  33.     MyStruct m_strct;
  34. };