Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One header for multiple cpp-files

Tags:

c++

Let's assume I have 3 cpp-files:

Main.cpp
First.cpp
Second.cpp

Now i want to use functions from First and Second in Main. Is there something to complain about, if I used only one header-file for both cpp-files and their functions?

Could there be any problems, when using the header-file in First, because I need a Function from Second in First?

like image 313
xamiax Avatar asked May 28 '14 12:05

xamiax


People also ask

How to add a header file in CPP?

Adding a Header File works the same as how we added another CPP source file (Square.cpp) NOTE: Use a .h suffix when naming your header files. Create a new item. By right clicking Project in solution explorer then click Add and in next option menu click on new item. This time select Header File (.h) File.

Can I use one header file for multiple functions in C++?

As far as C++ goes, there won't be any issues with using one header file and splitting the actual implementations of the functions between 2 files.

What are the types of header files in C++?

There are of 2 types of header file: 1 Pre-existing header files: Files which are already available in C/C++ compiler we just need to import them. 2 User-defined header files: These files are defined by the user and can be imported using “ 3 include”. More ...

How do I edit more than one header file in Visual C++?

Although Visual C++ only edits one header file for any given .RC file, Visual C++ supports references to symbols defined in additional read-only header files. Using the Resource Includes command from the View menu in Visual C++, you can specify any number of additional read-only header files as Read-Only Symbol Directives.


1 Answers

As long as you follow the ODR - One Definition Rule and every declaration is consistent, you will be fine.

Headers are usually meant to provide declarations for functions and other stuff, the linking phase (except when there's something a bit more involved like templates) will take care of resolving those dependencies.

I'm not saying anything on the design - not enough info provided.

like image 153
Marco A. Avatar answered Sep 27 '22 18:09

Marco A.