1

i made small program which does some functions and i tested it and it worked as i wish.
Then i add its .h and .cpp files to another program to use it but when i add the .cpp file it gives me 100s of errors related to boostmultiindex which i use in the added .cpp file.
i do not know what is happening.
the errors include the following"this is sample of errors":

Error   C2516   'boost::mpl::if_<C,F1,F2>::type': is not a legal base class


Error   C2039   'type': is not a member of 'boost::iterators::iterator_category_to_traversal<int>'  


Error   C3203   'type': unspecialized class template can't be used as a template argument for template parameter 'U', expected a real type  


Error   C2653   'safe_mode': is not a class or namespace name   
Error   C2143   syntax error: missing ',' before '<'

i did not attach code or files because i do not know where to start.
i can update the post based on any guidance.

update:
i think the problem is related to certain header file which i put in it most includes for all my cpp files.
this might lead to cyclic dependency problem which might led to ignoring some includes.
because when i exclude this large include file the errors are much decreased.
i will try to reorder the includes and see if they make difference.

update:
now i commented two lines in the large include file and it removed the errors related to this problem.
the two lines are:

//??#include "modules/utils/utils.h"
//??#include "modules/utils_dst/utils_dst.h"

i do not why these two lines makes these errors
is it related to the fact that the two files are in subdirectories???

ahmed allam
  • 377
  • 2
  • 15
  • 1
    Which compiler are you using? Have you copied the relevant flags for the added file? – unDeadHerbs Apr 06 '20 at 10:23
  • 1
    It looks like you're missing quite a few #includes. Did this file include any other files in your old project, that might've included a file you need? – Anonymous1847 Apr 06 '20 at 10:25
  • Really hard to say what is wrong without seeing your code. Try and produce a small a version of your new cpp file as possible that still has some errors and post it here. – john Apr 06 '20 at 10:47

1 Answers1

3

Make sure of the following:

  • When including the .h and .cpp files that you have the full path not just the name of the file.

  • There are no variables, functions, etc. having the same name/signature in both the files your including and the project file you are including to. If there is, then use namespace to differentiate between conflicts.

  • You have added all dependencies of the files you want to include to the file you want to include into.

Khaled Ismail
  • 315
  • 1
  • 2
  • 17
  • i think the problem is related to certain header file which i put in it most includes for all my cpp files.this might lead to cyclic dependency problem which might led to ignoring some includes.because when i exclude this main include file the errors are much decreased.i will try to reorder the includes and see if they make difference.+1 – ahmed allam Apr 06 '20 at 12:34
  • You can use `ifndef` to make sure multiple includes of the same .h are handled, so a file will be included once during precompilation – Khaled Ismail Apr 06 '20 at 12:49
  • You should not put full paths in include statements, that's what your build system is for. More important is to make sure you have header guards and that each header file includes any headers that it requires. – stark Apr 06 '20 at 18:24