0

I decided to try STL and use a vector instead of a custom made growable array class. The problem is that I can't get anything to compile. If I do something like this:

#include "stdafx.h"
#include <vector> 

std::vector<PITEMID_CHILD> APIDL;

I get a bunch of messages similar to this:

1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\cstdint(23): error C2039: 'int_least8_t': is not a member of '`global namespace''

If I change to this:

#include <vector> 
#include "stdafx.h"

std::vector<PITEMID_CHILD> APIDL;

I get this:

1>x:\win32testing\vectortest\vectortest.cpp(4): error C2039: 'vector': is not a member of 'std'

Inside of stdafx.h is this:

#pragma once

#include <windows.h>

#include "targetver.h"

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <shlobj.h>
#include <exdisp.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <atlbase.h>
#include <atlalloc.h>
#include <CommonControls.h>
// reference additional headers your program requires here
#include <CommCtrl.h>

Any idea what is going on?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user3161924
  • 1,849
  • 18
  • 33
  • What happens if you try `std::vector APIDL;` and remove `#include "stdafx.h"`? – Galik Apr 03 '19 at 00:36
  • 1
    `// reference additional headers your program requires here` -- Did you follow these directions? Admittedly, I avoid all of that precompiled header stuff due to the headaches it causes. – PaulMcKenzie Apr 03 '19 at 00:36
  • I got rid of the precompiled headers and put everything in the .cpp file. That just ended up with the long line of: `1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\cstdint(23): error C2039: 'int_least8_t': is not a member of '``global namespace''` items. Now I tested with only including and it does the same, so it must be some project setting? I tried C++ 14 and C++17 under language and still didn't work. – user3161924 Apr 03 '19 at 02:33
  • Please make a [mcve]. In C++ you should be including C header files by prefixing their name with a `c` and without the `.h`, such as ``. `int_least8_t` should be part of the `std` namespace. If you're using precompiled headers, the line including it needs to be the first thing in the file and anything before it will be ignored. – eesiraed Apr 03 '19 at 04:29
  • This doesn't answer your question, but I recommend not using `stdafx.h` and instead just deleting that file entirely. So far I've always found (precompiled) universe headers to be more trouble than they are worth. – Cornstalks Apr 03 '19 at 05:50
  • I agree -- get rid of `stdafx.h`, turn off precompiled headers, and include the proper headers yourself. That mess of headers `stdafx.h` is including is almost, if not just as bad as the [#include ](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) stuff we see here. – PaulMcKenzie Apr 03 '19 at 17:26

1 Answers1

0

From wikipedia documentation:

Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.

The best solution is to get rid of precompiled headers.

And for your C2039 error, it doesn't seem to be a result of line std::vector<PITEMID_CHILD> APIDL;. int_least8_t is a type defined in cstdint (stdint.h). It seems you haven't included this header file in your project.

amirali
  • 1,888
  • 1
  • 11
  • 32