c++default-constructorobject-files

When do object files contain code for class?


I was just curious about the question, but couldn't find the answer in the Internet.

Let's suppose we have simple header:

// SimpleHeader.h
class SimpleClass
  {
  int i;
  }

As we know, the default constructor is automatically generated for this class.

Now I have 2 more files:

// First.cpp
#include <SimpleHeader.h>
// ...
SimpleClass a;
// ...

and

//Second.cpp
#include <SimpleHeader.h>
// ...
SimpleClass b;
// ...

Will both First.obj and Second.obj contain code for the class?


Solution

  • From the standard: If you do not write any constructors, a default constructor will be provided for you, and this default constructor is defined inline and equivalent to an empty constructor T::T() {}.

    I'm pretty sure that [edit]your thus inlined constructor will not actually result in any machine code at all.