2

I am new to C++ and I am debugging one problem where there is a allocate.h file which is included by main.cpp file. Now the allocate.h file has first line like this : #include <memory.h>. and when I try to compile main.cpp I get an error message saying

Microsoft Visual Studio 11.0\ VC\ include\ typeinfo (153) : error
C2504 exception base class undefined

But when I change that first line to : #include <memory> then main.cpp compiles fine. Thats when I started to search the web for difference between these two styles of including files and I haven't found any detailed explanation yet. If anybody can explain the difference between including a .h file and a memory standard header, that would be really helpful.
Is it because #include<memory> is more thread safe ? or is it because its just the way in c++ to include files.

Also I am using cmake to include my project in the llvm's generated solution. When generating my .vcxproj file it includes _HAS_EXCEPTIONS=0; in the <PreprocessorDefinitions> tag in it. If I use the earlier declaration #include<memory.h> and remove _HAS_EXCEPTIONS=0; from the <PreprocessorDefinitions> tag then the project compiles fine. How is all this connected ? Can somebody help me connect the dots ?

Sam
  • 7,252
  • 16
  • 46
  • 65
voidMainReturn
  • 3,339
  • 6
  • 38
  • 66
  • 2
    `memory.h` isn't a standard library header. – chris Apr 16 '14 at 02:12
  • @chris : then visual studio should prompt me saying header file not found. It doesn't do that either. and header.h is present inside `C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include` – voidMainReturn Apr 16 '14 at 02:19
  • Just because it isn't a standard library one doesn't mean VS can't have extras. Anyway, not being a standard library header means that its purpose is not the same as ``. – chris Apr 16 '14 at 02:22

2 Answers2

8

<memory.h> and <memory> aren't different styles, they are two completely different headers.

<memory.h> looks like it's an internal header used by MS's C library, you shouldn't be including it, use the standard C++ header <memory>.

user657267
  • 20,568
  • 5
  • 58
  • 77
1

After writing this answer I found this SO question that I think is relevant.

This is nothing to do with thread safety AFAIK. The standard C++ headers are as below from the reference, 17.6.1.2 Headers:

Table 13 — C++ library headers

<algorithm> <fstream> <list> <regex> <typeindex>
<array> <functional> <locale> <set> <typeinfo>
<atomic> <future> <map> <sstream> <type_traits>
<bitset> <initializer_list> <memory> <stack> <unordered_map>
<chrono> <iomanip> <mutex> <stdexcept> <unordered_set>
<codecvt> <ios> <new> <streambuf> <utility>
<complex> <iosfwd> <numeric> <string> <valarray>
<condition_variable> <iostream> <ostream> <strstream> <vector>
<deque> <istream> <queue> <system_error>
<exception> <iterator> <random> <thread>
<forward_list> <limits> <ratio> <tuple>

As others have said, memory.h is not one of them.

For completeness, here are the C++ standard headers for C library facilities.

Table 14 — C++ headers for C library facilities

<cassert> <cfloat> <cmath> <cstddef> <ctgmath>
<ccomplex> <cinttypes> <csetjmp> <cstdint> <ctime>
<cctype> <ciso646> <csignal> <cstdio> <cuchar>
<cerrno> <climits> <cstdarg> <cstdlib> <cwchar>
<cfenv> <clocale> <cstdbool> <cstring> <cwctype>
Community
  • 1
  • 1
codah
  • 466
  • 4
  • 14
  • 1
    There's still `` and `` etc. which are perfectly standard, but it's not in those, either. – chris Apr 16 '14 at 02:22