title: How to pass a struct to a class in c++?
body: <p>I am new to c++ and this one has me stumped. I want to pass a struct to a class (I know they are technically the same) so the class can access the data in the struct. I don't mind if it is passed as a reference or a copy as there will be no changes to the struct within the class. Having said that a reference would probably be better for performance. I can get it all to work fine if I pass the members of the struct individually but the real version will have about 30 members so passing them individually isn't the best option.</p>
  
  <p>My main cpp:</p>
  
  <pre><code>#include "stdafx.h"
  #include "myClass.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  struct foo
  {
      int num;
      double dbl;
  };
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      foo bar;
      bar.dbl=3.14;
      bar.num=42;
      baz qux();  //bar needs to be passed here
      cout&lt;&lt;qux.getSum()&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>Class header:</p>
  
  <pre><code>using namespace std;
  
  class baz
  {
  public:
      baz();  //This is where type of bar (foo) is declared
      void setSum(int, double);
      double getSum();
  private:
      double sum;
  };
  </code></pre>
  
  <p>Class cpp:</p>
  
  <pre><code>#include "stdafx.h"
  #include "myClass.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  baz::baz()  //this is where bar is called
  {
      setSum(bar.num, bar.dbl);
  }
  
  void baz::setSum(int num, double dbl)
  {
      sum=num*dbl;
  }
  
  double baz::getSum()
  {
      return sum;
  }
  </code></pre>
  
  <p>So the nub of the question is, how do I get bar into baz?</p>