title: Reuse of class in file with main()
body: <p>How can I reuse a class that is in a file that already has a main method? E.g. I would like to use struct foo that another developer wrote in foo.cpp in my own program, main.cpp:</p>
  
  <pre><code>//-- foo.cpp --
  struct foo {
    int bar;
  };
  int main() {
    return 0;
  }
  //-- end foo.cpp --
  
  //-- main.cpp --
  #include "foo.cpp"
  int main() {
    foo f;
    f.bar = 1;
    return f.bar;
  }
  //-- end main.cpp
  </code></pre>
  
  <p>main.cpp will not compile using g++ 4.4.4, giving the errors:</p>
  
  <pre><code>main.cpp: In function "int main()":
  main.cpp:2: error: redefinition of "int main()"
  foo.cpp:4: error: "int main()" previously defined here
  </code></pre>
  
  <p>I cannot extract the main method from foo.cpp because I do not control that code. In the actual codebase I am dealing with, struct foo is more complicated so I cannot copy it into main.cpp, since it would be unmaintainable. </p>