Answer the question
In order to leave comments, you need to log in
Where is the best place to include header files?
For example:
I have a class described in MyClass.h and its implementation in MyClass.cpp
The class description requires only string
//MyClass.h
#pragma once
#include<string>
class MyClass {
public:
std::string ExampleFunction();
}
//MyClass.cpp
#include "MyClass.h"
//Дальше описание тела
Answer the question
In order to leave comments, you need to log in
Here is an example of a good answer.
In short: the inclusions in the header should be as few as possible, while it should include all the headers necessary for the smooth operation of the code described in it.
In your case, if vector is used exclusively in the implementation and does not show itself in any way in the description of blackbox 'a, you need to include it in .cpp
I’ll add to teugen that if you don’t use a class / structure value, but a pointer to it, then instead of including another header, you can insert a class declaration into the header:
#pragma once
class ExampleClass;
class MyClass {
public:
ExampleClass* ExampleFunction();
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question