Linked Questions
109 questions linked to/from Why have header files and .cpp files?
0 votes
1 answer
101 views
Why I have to use header file in separate file except main file? [duplicate]
The header's file content is put where .h file is used. Why use add.h in add.cpp? In case without using header file add.cpp // There is not declaration int add(int x, int y); int add(int x, int y) { ...
-1 votes
1 answer
110 views
Cpp linking/header, why is it done this way? [duplicate]
I'm new to c++ and I have 'actually' learned a lot these past days. I just learned how to link multiple files today or what I think is called, using "headers". My question is related to headers and ...
0 votes
1 answer
122 views
Why use a C++ header file? [duplicate]
I understand the header file contains all the prototypes of every function contained in the implementation file; but what is the real purpose? Is it because when another program calls on the class, it ...
1 vote
1 answer
89 views
Why make new header files when you can just use C files? [duplicate]
I was working with sockets , and i noted that a lot of the code i wrote repeated in different programs , so i wrote functions for most of the stuff that i did and saved them in a ".c" file without a ...
0 votes
3 answers
110 views
Resolve circular dependancy when using a Singleton in C++ [duplicate]
So I have a problem when using a singleton Game class and the Story class. Game.hpp #ifndef GAME_HPP #define GAME_HPP #include <memory> class Phase; // Forward declaration class Game { ...
1 vote
0 answers
98 views
Are header files only for classes? [duplicate]
I'm learning C ++ and I have a question about header files. Are they only for classes? If I have some functions and want to use them in several files, should I write the declaration in the h file and ...
2 votes
0 answers
82 views
Why Should I User Header files in c++? [duplicate]
my first project in c++ (I use g++ on centos) from Python and c#, I use to split my program into few files, each class in different file. The most common reason i find, why use .h file, is ...
-4 votes
1 answer
79 views
Why use .h files when you can just put all in the .cpp fil? [duplicate]
I been searching a lot lately about header files and stuff and i always see the same things, but i dont get something, why use the .h header file when you can just throw the code on the .cpp file? ...
0 votes
0 answers
73 views
Purpose of header files in cpp [duplicate]
Why is there a need to include the header file of a class into the implementation file of the same class?? Does it serve a purpose?? Since i thought it is needed only where we need to use that class.
0 votes
1 answer
65 views
why create .h and .cpp headers [duplicate]
I came across this implementation of some code which requires us to create a header and then #include it in our source code. So my question is why we need to create a .cpp file along with the .h and ...
0 votes
0 answers
60 views
Is their a better way to implement class in c++? [duplicate]
When we write class in c++ we divide class into two part that header file and cpp file. In header file we define class and prototype Class.h class A{ public: void functionName(); }; Then we define ...
0 votes
1 answer
53 views
Pracitcal design difference between header and cpp files [duplicate]
Comming from a mostly Java background I recently started learning a bit of C++. I'm trying to create a class that describes a LinkedList. Since I want this class to be something like an external ...
0 votes
0 answers
48 views
(C++) Dont use header files [duplicate]
I'm having a general question about header files: In my project, which is not a library or plugin, but a standalone program, I don't use any header files - I am just using cpp files that I include in ...
0 votes
0 answers
41 views
Does every C++ implementation file need its own headers? [duplicate]
I'm a beginner to C++ and I am getting extremely confused trying to understand the benefits of the recommended practices regarding headers and implementation files. Say I have two implementation ...
0 votes
1 answer
42 views
use header file for sources instead using cpp file and .lib [duplicate]
Hello i have a code like this in c++: #include <iostream> using namespace std; namespace exercises { class String; ostream& operator<<(ostream&, const String&); istream&...