C++ Use of undeclared identifier 'make_unique' - c++

I am keep on getting the following error when I build,
use of undeclared identifier 'make_unique'
m_planet = make_unique();
My Header File which gives out the error,
#include "planet.h"
#include <memory>
using namespace std;
class PlanetBuilder
{
public:
PlanetBuilder();
virtual ~PlanetBuilder();
void createNewPlanetProduct() {
m_planet = make_unique<Planet>();
}
protected:
unique_ptr<Planet> m_planet;
};
#endif // PLANETBUILDER_H
I am running QtCreator 3.6.0 , tried on both Mac and Windows platforms and the error is consistent.. where am I going wrong?

make_unique requires #include <memory>
But since you have done that, I would think you are not using C++14 or above.
Try adding following flag on your make file.
-std=c++14

For current QT which is 5.7 I'm using a #include .
By following a link bellow you find out more. QScopedPointer link

Related

C++ Error C3646, C2059, and C2238 Visual Studio 2015 (Community) [duplicate]

This question already has answers here:
Resolve build errors due to circular dependency amongst classes
(12 answers)
Closed 7 years ago.
I have been trying for some time (in vain) to track down the cause of the following errors all thrown at the declaration of 'checkCollision()' in "PolygonGameObject.h" when I try to compile as a static library:
Error C3646 'checkCollision': unknown override specifier
Error C2059 syntax error: ')'
Error C2238 unexpected token(s) preceding ';'
In an attempt to track down the error, I have renamed the function, removed all function parameters, removed all content from the offending function (except a return statement returning an object created by the default constructor of the desired return type). For brevity, I have removed all content from the original program while still causing the same errors in an attempt to find the cause of the errors.
I am using Visual Studio 2015 Community running on Windows 7. I am compiling the source files as a static library. Below are the stripped down source files with which I have produced the error:
CollisionData.h
#ifndef COLLISIONDATA_H
#define COLLISIONDATA_H
#include "Vec2D.h"
#include "PolygonGameObject.h"
#include <list>
struct CollisionData
{
double penetrationDepth;
Vec2D collisionNormal;
std::list<std::size_t> involvedIndicesA;
std::list<std::size_t> involvedIndicesB;
CollisionData();
CollisionData(double penetrationDepth, Vec2D collisionNormal, std::list<std::size_t> involvedIndicesA, std::list<std::size_t> involvedIndicesB);
~CollisionData();
static CollisionData noCollision();
};
#endif
CollisionData.cpp
#include "CollisionData.h"
using namespace std;
CollisionData::CollisionData()
{
}
CollisionData::CollisionData(double penetrationDepth, Vec2D collisionNormal,
list<size_t> involvedIndicesA, list<size_t> involvedIndicesB):
penetrationDepth(penetrationDepth), collisionNormal(collisionNormal),
involvedIndicesA(involvedIndicesA), involvedIndicesB(involvedIndicesB)
{
}
CollisionData::~CollisionData()
{
}
CollisionData CollisionData::noCollision()
{
return CollisionData(-1, Vec2D(0,0), list<size_t>(), list<size_t>());
}
PolygonGameObject.h
#ifndef POLYGONGAMEOBJECT_H
#define POLYGONGAMEOBJECT_H
#include "CollisionData.h"
class PolygonGameObject
{
protected:
double restitution;
double density;
double invMass;
public:
PolygonGameObject();
virtual ~PolygonGameObject();
static CollisionData checkCollision();
};
#endif
PolygonGameObject.cpp
#include "PolygonGameObject.h"
#include "CollisionData.h"
#include <limits>
#include <cmath>
#include <algorithm>
PolygonGameObject::PolygonGameObject()
{
}
PolygonGameObject::~PolygonGameObject()
{
}
CollisionData PolygonGameObject::checkCollision()
{
return CollisionData();
}
Thanks for your time!
You have a circular include, where PolygonGameObject.h contains #include "CollisionData.h" and vice versa. That is not possible.
I can't see that any PolygonGameObject is used in CollisionData.h, so you could just remove the unneeded include from that header.

Is there a method to use gmpxx.h together with c++98?

Because of my project I need to use c++98 and gmpxx.h:
But even for a simple project, it doesn't work:
#include <gmp.h>
#include <gmpxx.h>
int main()
{
int xrange=5,yrange=5,component=5;
return 0;
}
The error message is:
I tried using the following compiling methods
libc++: support c++11 and thus work
libstdc++: only support c++98 and do not work
Is there a way to use c++98 to implement gmpxx? thank you :)
Detail of errors when using c98++ to implement:
The breaking line is:
cout<<r<<endl;
But it works in c++11:
The error report:

Strip pointer from void* for use in unique_ptr using statement?

I'm trying to compile a simple C++ program that uses some functions and datastructures from the Win32 API and Wincrypt:
#include <memory>
using std::unique_ptr;
#include <Windows.h>
#include <Wincrypt.h>
using CERTSTORE_ptr = unique_ptr<CERTSTORE, decltype(&:: CertCloseStore)>;
int main(int argc, char* argv[])
{
return 0;
}
When I attempt to compile it, I get errors at the using CERTSTORE_ptr ... line. The errors:
test.cpp(18): error C2873: 'CERTSTORE_ptr' : symbol cannot be used in a using-declaration
test\certstoreexporttest.cpp(18): error C2513: 'int' : no variable declared before '='
test\certstoreexporttest.cpp(18): error C2065: 'CERTSTORE' : undeclared identifier
...
The problem appears to be with CERTSTORE and HCERTSTORE, which is typedef'd as:
typedef void *HCERTSTORE;
How do I declare the using statement so I can enjoy the automatic cleanup? (I'm trying to avoid the __try\__finally).
Or is this simply the wrong approach and should be abandoned? (I'm ready to go back to __try\__finally so I can finish up this test program).

syntax error : missing ';' before identifier 'iDlg'

I am trying to get a dialog box [import] to launch from another dialog box [baseline].
I am including the required ".h" files however I am simply not able to create an instance of the import class. The error I get is this:
Error 1 error C2146: syntax error : missing ';' before identifier 'iDlg' h:\shaunak\projects\sar_ccd\sar_ccd\baseline.h 202 1 Sar_CCD
The line of code that causes this [baseline.h]:
#include "Markup.h"
#include<stdio.h>
#include<math.h>
#include "baseline_func.h"
#include "resource.h"
#include "Functions.h"
#include <stdlib.h>
#include "Sar_CCDDoc.h"
#include "Sar_CCDView.h"
#include <vector>
#include "MemAlloc.h"
#include "ReadFiles.h"
#include<vector>
#include<map>
#include "afxwin.h"
#include "import.h"
#include "Geocode.h"
**<SNIP: Taking out the irrelevant lines>**
afx_msg void OnDestroy();
virtual void PostNcDestroy();
afx_msg void OnBnClickedNxtBase();
CButton nextBaseline;
import iDlg; //doesnt work!
CGeocoding cx; //works!!!
};
However, if I create and instance of another class [Geocoding] using the same sysntax like so, it works fine:
#include "Geocoding.h"
CGeocoding cx;
Please help me figure out why.
Full code:
baseline.h: http://freetexthost.com/on06wref6c
import.h: http://freetexthost.com/x4e4dkwrve
In Visual Studio there is a keyword import or #import rather used to import a COM DLL and is used for other things as well. I guess you are experiencing a name collision there.
In order to get around it place your class import in a namespace
import.h
namespace myimport
{
class import : public CDialog {
...
};
};
import.cpp
namespace myimport
{
...
};
then when you use it
myimport::import iDlg;
that should solve the issue, although renaming it to something else than "import" would be the better way to go.
import is not a keyword or type in C++. Therefore you get a syntax error because the compiler doesn't recognize import.
To create an instance of another class you have to properly declare it, e.g.:
class baseline : public CDialog
{
// ...
CDialog *iDlg; // Pointer to imported dialog
};
Remember to initialize the pointer to the actual dialog.

C++ compilation error when adding windows.h

I need to write small tool in C++
I've never used C++ as programming language before (I have couple years of Java dev experience) and .NET
I've started a new project in VS , when I am adding in my Header file of my class
#include <windows.h> I am getting the following error:
Error 1 error C2143: syntax error : missing ';' before '*' c:\program files\microsoft sdks\windows\v7.0a\include\servprov.h 96 1 CppLog
For now my class even doesn't have any real functions and looks like
in header
class TheTool
{
public :
void Foo();
};
in cpp
void TheTool::Foo(){};
and the project doesn't get compiled.
plz any suggestions ? Maybe a compiler doen't set up good ?
this is how the Header file looks like
#pragma once
#include "stdafx.h"
#include <stdio.h>
//#include <Windows.h>
//#include <winuser.h>
//#include <windowsx.h>
//#include <time.h>
class TheTool
{
public :
void Foo();
};
When I am uncommenting the include I am starting to get this compilation error.
BTW , how can i know the compiller setting ?