Question

I'm wondering to code a C++ application with a header-only layout like the following:

// code3.h
#include <iostream>
class code3
{
public:
  void print()
  {
    std::cout << "hello " << std::endl;
  }
};

// code2.h
#include "code3.h"
class code2
{
public:
  void print()
  {
    code3 c;
    c.print();
  }
};

// code1.h
#include "code3.h"    
class code1
{
public:
  void print()
  {
    code3 c;
    c.print();
  }
};

// main.cpp
#include "code1.h"
#include "code2.h"

int main()
{
  code1 c1; 
  c1.print();

  code2 c2; 
  c2.print();
}

The only cpp file will be the main file. The rest of the code will be placed in header files.

I would like to know if there is some kind of performance problem with this approach. I know that defining the methods in the class declarations inlines them, but as it will be only one cpp file, the inline methods won't be duplicated. I just want to focus my question on the performance. I'm not talking about extensibility, legibility, maintenance or anything else. I want to know if I'm missing something with this approach that could generate a performance problem.

Thanks!

No correct solution

OTHER TIPS

You will find that this becomes rather unpractical when your project has several hundred files (or more), and ALL of the code has to be recompiled EVERY time you change something.

In a small software project, there's little reason to have different source files, but there is no huge drawback of having more than one source file.

When the source starts to be more than a dozen files, compile time starts to increase. It's also much harder to isolate functional groups of code, which in turn affects the ease with which you can take one lump of code and use it in a different project - which is often a useful thing when working on code.

Last time I asked this question, I got a TON of useful answers: http://www.daniweb.com/software-development/cpp/threads/423106/separate-headers-from-source

Basically I asked why I should separate my source from headers because I also used to hate having "extra" files and switching back and forth between the header and the source. I think the answers I got may be useful for you so I'm just going to leave that link above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top