#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <functional>
#include <limits>
#include <math.h>
#include "DataStreamClient.h" //[x]
#include "stdafx.h"
using namespace ViconDataStreamSDK::CPP;
{ ...
This is the start of my file that uses the header file ViconDatastreamSDK.h but in every instance that a class from the file is called Visual Studio gives the error:
'ViconDataStreamSDK': is not a class or namespace name
The solution explorer shows that the file is included in the external directories.
How do I get VisualStudio to recognize these classes?
Related
I have a problem with the inclusion of header "queue" via a precompiled header file in c++ (VS 2019).
My Visual Studio solution consists of two projects, one engine project (static library) and one sandbox project (links the engine project) to test the engine's functionality. The engine project uses a precompiled header file, in which i just included "queue" since i am implementing a message system. Both projects are using C++17.
Visual Studio compiles the engine project without a problem, the sandbox project then throws the following error while compiling:
Error C2039 'queue': is not a member of 'std' (path\to\engine\message_handler.h)
As soon as I include "queue" directly in message_handler.h (see code excerpt), the error vanishes and the project starts up just fine.
I have been using the precompiled header for almost a year now and never had any problems.
Can anyone help me with this?
Following are the relevant excerpts from my code.
Precompiled header:
#pragma once
//memory
#include <memory>
//timing
#include <chrono>
#include <ctime>
//container
#include <vector>
#include <queue>
#include <unordered_map>
#include <array>
//string and streams
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
//misc
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <random>
message.h
struct Message
{
Message(){}
uint32_t id_;
};
message_handler.h
#pragma once
//#include <queue> //fixes the issue
#include "message.h"
using UnqPtr = std::unique_ptr<Message>;
class MessageHandler
{
public:
MessageHandler();
private:
static constexpr uint32_t maxMessages_ = 10000;
std::queue<UnqPtr<Message>, std::vector<UnqPtr<Message>>> msqQueue_;
};
message_handler.cpp
#include "trpch.h" //precompiled header
#include "message_handler.h"
MessageHandler::MessageHandler()
{
//reserve space in the underlying vector
std::vector<UnqPtr<Message>> queue;
queue.reserve(maxMessages_);
msqQueue_ = std::queue{queue};
}
I'm using openCV-3.2.0 and getting an identifier undefined error when initializing the line :
CvRTrees rtrees;
I think i have added all the necessary header files. So why am i getting this error?
#include <stdio.h>
#include<conio.h>
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.h>
#include <opencv/ml.h>
#include <opencv2/core/core.hpp>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <math.h>
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <exception>
#include <array>
#include "opencv2/ml/ml.hpp"
using namespace std;
using namespace cv;
This class exists in OpenCV 2.4.x, However it is not available in newer versions of OpenCV like 3.2.0. Check here the list of all cv::ml classes for OpenCV 3.2.0. I suggest you to use RTrees instead. To do this you do not need to include all headers, just include the machine learning module:
#include "opencv2/ml/ml.hpp"
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 ?
<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>.
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>
Intellisense is broken with this code, everything is undefined to Intellisense from tree header:
#include "tree.h"
#include <iostream>
#include <ctime>
#include <string>
#include <list>
But when I move my own bst implementation header file down a bit, Intellisense starts working again.
#include <iostream>
#include <ctime>
#include <string>
#include <list>
#include "tree.h"
Why is this?
I'm working on implementing DirectSound into a program, but it requires dsound.h which requires sal.h, and for whatever reason I'm having trouble getting g++ to recognize the fact that I have sal.h and it is in the path file and I can even type in the direct command sal.h and command prompt will open sal.h. But when I compile with
g++-3 World.cpp -c
I get
dsound.h:13:17: sal.h: No such file or directory.
followed by thousands of errors from dsound.h resulting from the lack of sal.h. I'm just using notepad, g++, and command prompt, do I need to be in VC++ for sal.h to work? Is there any way to use DirectSound without it?
Here's the opening to the code I'm compiling, just in case:
#include "WorldEntity.h"
#include "MBox.h"
#include <D3D9.h>
#include <d3dx9.h>
#include <string>
#include <sstream>
#define _USE_MATH_DEFINES
#include <math.h>
#define KEYDOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
using namespace std;
World::World()
{
//Etc
Here is the beginning of WorldEntity.h, the included file that includes dsound.h:
#ifndef WORLDENTITY_H
#define WORLDENTITY_H
class Entity;
class HUD;
#include "Enums.h"
#include "Object.h"
#include "Inventory.h"
#include "AI.h"
#include "Item.h"
#include "Sector.h"
#include "MBox.h"
#include "Particle.h"
#include "Sprite.h"
#include <windows.h>
#include <windows.h>
#include <mmsystem.h>
#include <mmreg.h>
#include <dsound.h>
#include <string>
#include <D3D9.h>
#include <d3dx9.h>
#include <cstdlib>
#include <ctime>
using namespace std;
enum FontIndex
{
//Etc
The command path is not the same as the include path. You have to add the -I flag to GCC to tell it where to find header files:
g++-3 -IC:\some\path World.cpp -c