Compiler error for std::string in c++ builder XE3 project - c++

I am working on a service application in c++ builder XE3.
I am getting compiler error for std::string if I add this line:
string a = string("abcd") + "xyz";
Error output is as follows:
[bcc32 Error] string(141): E2285 Could not find a match for 'move<_Ty>(string)'
Full parser context
string(140): decision to instantiate: string std::string + <char,char_traits<char>,allocator<char> >(string &&,const char *)
--- Resetting parser context for instantiation...
svcmain.cpp(21): #include C:\Program Files\Embarcadero\RAD Studio\10.0\include\boost_1_39\boost\tr1\tr1\string
string(20): #include c:\program files\embarcadero\rad studio\10.0\include\../include/dinkumware/string
string(7): namespace std
string(140): parsing: string std::string + <char,char_traits<char>,allocator<char> >(string &&,const char *)
I tried to add #include <utility> just above #include <string> but still getting same error.
Instead, if I split the line into two as follows, it compiles without errors.
string a = string("abcd");
a += "xyz";
OR
string b = string("abcd");
string a = b + "xyz";
Its not practical to use this workaround as I have to use existing code which is getting large no of errors. Same code works without errors in other XE3 project.
Any ideas how to fix this error?

I found the fix in the other project. Setting the "backward compatibility" option to false fixed the error.
You can find the checkbox in - Project options -> C++ compiler -> Compatibility -> General.
This was initially set to true.

Related

AppCode falsely reporting errors in C++ editor

I'm trying out AppCode and CLion for developing an C++ app on macOS. CLion seems to work well, but it's not obvious how to build a Cocoa/AppKit app, or an iOS app. I downloaded a trial of AppCode, thinking it would have the same C++ engine, but it chokes on a lot of code.
A couple examples:
It thinks there is no conversion from char * to std::string.
It can't see the overloads in the popular fmt library.
CLion parses this stuff. Maybe I should work on getting that to build a macOS app. Is there a way to get AppCode to parse this properly and not incorrectly report errors with red underlines and popups? It compiles and runs fine. It's the editor having problems and showing "errors" in the code.
#include <string>
#include "fmt/format.h"
int main(int argc, const char * argv[]) {
int x = 10;
int y = 25;
std::string name = "Godzilla";
fmt::print("x + y = {}, name = {}", x+y, name);
return 0;
}
Screenshot from AppCode.
The errors reported incorrectly by the editor are:
Types 'std::string' and 'const char[9]' are not compatible.
Parameter type mismatch: Incompatible pointer types 'FILE *' and 'const char[22]'

How to detect USRP usb type?

When i include uhd/usb_control.hpp in my main.cpp :
#include <uhd/transport/usb_control.hpp>
/* Some other includes */
int main (void)
{
uhd::transport::usb_control::sptr usbSpeed;
usbSpeed = uhd::transport::usb_control::make(handle, 0);
/* `handle` is a `usb_device_handle::vid_pid_pair_t` */
}
I got error from here:
static sptr make(usb_device_handle::sptr handle, const int interface);
Error:
unexpected token struct. Did you forget a ';'
struct: missing tag name
And another strange error in:
usbSpeed = uhd::transport::usb_control::make(handle, 0);
Error:
Cannot convert argument 2 from int to const int
The only implementation that i find for uhd::transport::usb_control::make is uhd/transport/usb_dummy_impl.cpp which only throw an exception.
Environment information:
Compiler: MS Visual Studio 2017
OS: MS Windows 10
C++ Standard: 17
How to fix those errors ? I only what to detect the USRP usb type. For this i read the uhd source code and i find the uhd/transport/usb_control.hpp, But I have encountered those errors.
maybe the cause of this unexpected behavior is related to your included files and a conflict between some of them, as you mentioned in addition of #include <uhd/transport/usb_control.hpp> you have some other includes. i suggest move this include line upper and lower of other includes and test your code again.
wish my suggest be useful.

GDAL Library Header Files Error and Warningsin With Visual Studio 2019

I am using GDAL in visual studio 2019 community version,and I used the sample code in the their official site which is down below,the program compiles, runs and outputs fine, but I got a list of errors and warnings, I don't know if I should ignore them or make some change on header files, anyone encounter issues like this before? hope someone could give me some advice, thank you.
sample code:
/*gdal_test*/
#include <iostream>
#include <gdal_priv.h>
#include <cpl_conv.h>
using namespace std;
int main()
{
const char* pszFile;
GDALAllRegister();
pszFile = "E:/190807/mosaic_data/S2_1_170215.tif";
GDALDataset* poDataset = (GDALDataset*)GDALOpen(pszFile, GA_ReadOnly);
GDALRasterBand* poBand = poDataset->GetRasterBand(1);
int xsize = poBand->GetXSize();
int ysize = poBand->GetYSize();
cout << xsize << endl;
cout << ysize << endl;
system("pause");
return 0;
}
error list mainly contains these three main issue:
Error (active) E0065 expected a ';' gdaltest C:\MSVC_Library\GDAL\warmerda\bld\include C:\MSVC_Library\GDAL\warmerda\bld\include\ogr_geometry.h 387
Error (active) E1455 member function declared with 'override' does not override a base class member gdaltest C:\MSVC_Library\GDAL\warmerda\bld\include C:\MSVC_Library\GDAL\warmerda\bld\include\ogr_geometry.h 1139
Warning C26812 The enum type 'CPLErr' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). gdaltest C:\MSVC_Library\GDAL\warmerda\bld\include C:\MSVC_Library\GDAL\warmerda\bld\include\cpl_error.h 244
should I change the syntax in header files? will change it effect something? Or should I just ignore these errors?
You state that your program, "compiles, runs and outputs fine," so, the errors you are seeing are being reported by the "Intellisense" tool in Visual Studio.
To stop displaying these, go to the "Error List" window and select the "Build Only" option:
The C26812 warning message can be disabled as described in my answer to your recent question.

Compiling problems with wstring in c++

I need to refactor a .dll for a Zinc based Flash application.
After copy&paste a class from the master to the branch, I'm getting some strange compiling errors:
GameInfo.h(15): error C2146: syntax error : missing ';' before identifier 'm_wsVersion'
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
The addressed code:
// removed the comments
#include "stdafx.h"
#include <string.h>
class GameInfo {
public:
UINT m_uiGameId;
wstring m_wsVersion; // Line 15
UINT m_uiCheckSum;
wstring m_wsFilePath; // Same error report as on line 15
public:
static BOOL createFromFile(wstring path, GameInfo &target); // error "error C2061: syntax error : identifier 'wstring'" thrown
};
I use Visual Studio 2010 and in the IDE itself everything is okay, no syntactical errors or something like that. And as said I did not touch the code, headers seem fine.
Has anyone a clue what about this error?
Try using the string header, and qualifying the namespace:
#include <string>
class GameInfo {
....
std::wstring m_wsVersion;
};
#include <string> is the right standard include in C++ for string classes and use std::wstring.
I strongly recommend AGAINST using a using namespace std; inside one of your headers, as you would force anybody using the header to pull in the std stuff into the global namespace.

SQLite3 object not understood?

Now I'm geting an error:
1>c:\development\document_manager\document_manager\storage_manager.h(7) : error C2079: 'storage_manager::db' uses undefined struct 'sqlite3'
with
#pragma once
#include "sqlite3.h"
class storage_manager
{
sqlite3 db;
sqlite3** db_pp;
public:
void open()
{
sqlite3_open("data.db", db_pp);
}
};
Old Question:
Hi everyone. I downloaded sqlite-amalgamation-3_6_13.zip from http://www.sqlite.org/download.html, but I'm not able to compile it in my project. I receive many errors like:
c:\pathtoproject\sqlite3.c(11337) : error C2440: '=' : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
c:\pathtoproject\sqlite3.c(12023) : error C2440: '=' : cannot convert from 'void *' to 'sqlite3_int64 *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
What do I need to do to compile my project properly? Thanks!
Edit:
I don't want to compile the whole program as C, I just want to compile three files as c, is this possible?
EDIT: FIXED! I created an new project.
It looks like you might be trying to compile a C program using a C++ compiler. While there is a lot of C code which is also valid C++, they are different languages.
Your compiler may have some switch or setting to compile C code. Check your compiler documentation.
You need to compile the file as C code rather than C++.
Right click on either the project or just the .c file, and in properties, make sure it is set to compile as C, rather than C++. (You may want to set this setting just for the file, not the entire project)
Doesn't the compiler tell you what to do? You need an explicit cast:
void *pv = /* some value */;
char *pc = (char*) pv;
This is of course not a problem in C, but an issue of C++.