Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best workflow to keep cpp files and header files in sync?

Tags:

c++

I'm trying to learn C++ for Qt development, and I'm a little scared of header files. What I'd like to know is, what's the best workflow for keeping *.cpp and *.h files synched? For example, is the norm to write the class file and then copy the relevant info over to the header?

Sorry if this doesn't make any sense...I'm just looking for an efficient workflow for this.

Thanks!

  • Justin
like image 447
jgoney Avatar asked Jul 14 '10 23:07

jgoney


2 Answers

For example, is the norm to write the class file and then copy the relevant info over to the header?

While there is no single standard approach, its usually a good idea to:

  • first think about the public interface
  • put that in the header
  • implement in the source file accordingly
  • update the header if needed

Jumping straight into the implementation can make for a painful refactoring later on.

like image 133
Georg Fritzsche Avatar answered Oct 18 '22 01:10

Georg Fritzsche


So:

  • You'll get linker errors if something's in the header, used by a client, and not in the cpp.
  • You'll get compile errors if something in the cpp is not defined or is defined differently in the .h

What scenario are you worried about?

like image 3
David Gladfelter Avatar answered Oct 18 '22 02:10

David Gladfelter