vendredi 21 février 2020

Getting many include errors while converting C to C++ in a mixed codebase

I'm a little new to C++ and I have a question regarding converting C code into C++ code, as well as mixing C and C++ code.

For example, I'm refactoring a previous C file to a C++ file because I am now required to use a std::string in the header file's struct. It now looks as follows (firstClass.hpp):

struct firstClass
{
              .
              .
              .

    std::string test_string;

    firstClass();
    firstClass(const firstClass &c);
    ~firstClass();
};

And as a result, here's first-class.cpp:

#include "firstClass.hpp"

extern "C"
{
              .
              .
              .

     #include <errno.h>
     #include <assert.h>
     #include <stdlib.h>
     #include <string.h>
}

              .
              .
              .

Now here's my question: I have other files that previously included firstClass.h (Note: this is the C-variant) before I converted it to C++ code -- do these files need to also be converted to C++ code? Also, if additional files include these files mentioned above will they need to be converted as well? I guess to sum up my question: after converting this initial file to C++, how far down the chain of includes do I need to also convert those files?

Aucun commentaire:

Enregistrer un commentaire