0

This is a problem that seem to occur from time to time for me. The linter says that "namespace std has no member 'vector'" although the program compiles and runs fine. The only problem besides the annoyance is that I cannot use the ctrl-click feature on the GameObject-class. The linter (intellisense) does not find it. I have tried to run a clean solution and recompile, as well as delete the temp-folder and the hidden .vs- file to no avail.

#include "GameObject.h"
#include "GraphManager.h"
#include <vector>

class GameObjectManager
{
    static std::vector<GameObject> myGameObjects; 

    void CheckCollisions();
    static int myIDCount;


public:
    GameObjectManager() = default; 
    static void Init();
    static GameObject& GetGameObject(const int index) { return myGameObjects.at(index); };

    static void Update(const float aDeltaTime);

    static void Render(); 
};

enter image description here

Sasse
  • 1
  • 1
  • Some faulty installation of Visual Studio ? – Michael Chourdakis Dec 27 '21 at 16:10
  • 2
    Does this answer your question? [Visual Studio Code, #include saying "Add include path to settings"](https://stackoverflow.com/questions/37522462/visual-studio-code-include-stdio-h-saying-add-include-path-to-settings) –  Dec 27 '21 at 16:12
  • Only a complete C++ compiler can fully understand C++ code. Other non compiler-based tools, such as this "linter" may not be able to fully digest all C++ code, although I wouldn't expect something like that to choke on a plain, garden-variety, `std::vector`. – Sam Varshavchik Dec 27 '21 at 16:18

1 Answers1

0

Which linter are you using?

Basically a linter tries to "compile" - meaning to look at - your source code pretty much the same way the compiler does. But for this to work, the C++ "environment" - meaning: the include paths, predefined macros and compiler options - must be (nearly) the same as the ones the compiler uses.

For example: If you compile your code in "release" configuration, several predefined and "by-convention" macros are set, such as NDEBUG, _WIN32 and others. Other macros such as _DEBUG are not set.

The microsoft std::vector implementation depends heavily on such macros. Depending on the macros it enables or disables features such as different levels of iterator validation in debug builds etc...

When you use a (non-microsoft) linter and run "lint.exe" (or whatever it is), you must make sure (define on the linter command line), that "lint.exe" is started with the same set of macros, include paths etc... as the compiler cl.exe.

If that is not the case, the missing macros may well cause the linter to miss the entire std::vector definition.

Or - alternatively - the linter is not good enough to untangle the internal web of macros. The namespace std { } statement for example might not be written verbatim in <vector>, but might require macro expansion and possibly a lot of it. If the linter has problems doing that, vector might be defined somewhere, just not in a std namespace.

C++ is notoriously hard to parse by tools.

Which is why I would recommend using Microsofts "Code Analysis" Tool, since you are using the Microsoft Compiler anyway.

Hajo Kirchhoff
  • 1,969
  • 8
  • 17
  • The linter is Intellisense which usally works well with the Visual Studio compiler. I have edited my question in that regard. When I switch between debug and release mode the problem persists. Do you still think it could be a macro-related issue? – Sasse Dec 27 '21 at 16:47
  • Well actually, now I noticed that it only compiles in debug-mode. I will investigate it further. – Sasse Dec 27 '21 at 16:53
  • It seems that this intellisense-error was caused by a linker error similar to the issue described here: https://stackoverflow.com/a/51468383/17774610 – Sasse Dec 28 '21 at 14:49