Search code examples
c++vectormoduleinclusion

Inclusion vector module conflict c++


I have a problem with the inclusion of the vector module. It seems to there is a conflit with others modules. Here is the structure :

In the simulation.h :

#pragma once
#ifndef SIMULATION
#define SIMULATION

#include <ostream>
#include <sstream>
#include <string>

#include <algorithm>
#include <cstdlib>
// #include <vector>

#include "File.h"
...
void afficherResultat(std::vector<Client> sortie);
...
#endif

And the File.h file :

#pragma once

#ifndef FILE
#define FILE

#include <vector>

class File {
    ...
    std::vector<Client> l;
    ...    
};

#endif

And I get 108 errors starting with : C4091 warning and C4430, C2065, C4229 errors... Some people spotlight the order of the inclusions. Any Ideas ?


Solution

  • You are defining a macro for an identifier which is part of the standard library:

    #define FILE
    

    (see https://en.cppreference.com/w/cpp/io/c#Types for what FILE is).

    Doing so is forbidden and will cause very weird errors.

    Instead use names which are as unique as possible as include guards, e.g. INCLUDE_GUARD_FILE_H.

    If you have an include guard there is also no need for #pragma once which is a non-standard way of solving the double inclusion problem that the include guard is also supposed to prevent.

    Additionally you have not declared Client in File.h. Probably some #include for the header file defining Client is missing.