C2027 can't use Stringbuf in MVSC [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 days ago.
Improve this question
I've an issue using stringbuf in MVSC
stringbuf is a basic std type from iostream which is included above that block code.
for example a method using stringbuf reference :
`bool SJsonMon::Initialize(const stringbuf& DeviceP)
{
/*
******************************************************
*** Init lifetime monitor
******************************************************
*/
DeviceParameters = json::parse(DeviceP.str());
if (DeviceParameters["TypeElement"] == "LS14250")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS14250_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS14500")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS14500_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS17500")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS17500_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS26500")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS26500_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS33600")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS33600_MonitorLifetime_P;
}
mRL_MonitorLifetime_M.blockIO = &mRL_MonitorLifetime_B;
mRL_MonitorLifetime_M.dwork = &mRL_MonitorLifetime_DW;
/* Pack model data into RTM */ // Context to back up
// Initialization input output for step method
RL_MonitorLifetime_initialize(
&mRL_MonitorLifetime_M,
&mRL_MonitorLifetime_U,
&mRL_MonitorLifetime_Y);
// Pack Device parameters in json object
DeviceParameters = json::parse(DeviceP.str());
return 1;
}`
the error :
Erreur C2027 utilisation du type non défini 'std::basic_stringbuf<char,std::char_traits<char>,std::allocator<char>>'
Is someone can help about that issue?
Thanks a lot!
I used this code on stm32IDE and it worked and I decide to export the project on MVSC to simplify the DLL compilation.

Related

Using single else statement for multiple if conditions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am coding for an arduino project and i came across this problem, can anyone help me out!
if(condition1){
//my codes here
}
if(condition2){
//my codes here
}
if(condition3){
//my codes here
}
......
if(condition100){
//my codes here
}
else{
my codes here
}
I want to check all my if conditions, and execute the codes if the conditions are true, and run the else statement only if none of the if condition become true.
Note that i cant use else if because i want to check all the if conditions, and if none are true i want to run the else
If conditions are not dependent on each other
You can use a Boolean flag which is set in any of your ifs.
bool noPathTaken = true;
if ( condition1 ) {
noPathTaken = false;
// ...
}
if ( condition2 ) {
noPathTaken = false;
// ...
}
// ...
if ( noPathTaken ) { // this would be your "else"
// ...
}
must set off all else flag in each test
bool elseFlag = 1;
if(condition1){
elseFlag = 0;
my codes here
}
if(condition2){
elseFlag = 0;
my codes here
}
if(condition3){
elseFlag = 0;
my codes here
}
......
if(condition100){
elseFlag = 0;
my codes here
}
if (elseFlag) {
my codes here
}
because else gets binded only into preceding test operation, here if(condition100) {

PhysFS_init() returns non-zero with error: "no error"

Im experiencing a rather weird crash in my code and im unsure as to what causes it. Im trying to use PhysFS in my c++ code. the code below is part of a class and Visual Studio 2017 tells me that the crash appears in PHYSFS_mount() and subsequently in EnterCriticalSection(), which to my understanding has something to do with mutexes. Now from my understanding this should be correct (Note that the main calls initArchives() first)
physfs_initialized = false;
...
void scope::parse_archive(const std::string& archive_path, const std::string& path_in_archive)
{
assert(physfs_initialized);
m_archivePath = archive_path;
m_relativeArchivePath = path_in_archive.substr(1);
//fsx = std::filesystem or std::expiremental::filesystem whatever floats your boat
if(exists(fsx::path(archive_path))) return;
if(!PHYSFS_mount(m_archivePath.c_str(),"",0)) return;
const auto file = PHYSFS_openRead(m_relativeArchivePath.c_str());
if(file) m_isValid = true;
PHYSFS_close(file);
PHYSFS_unmount(m_archivePath.c_str());
}
...
void initArchives(char ** argv)
{
if (!PHYSFS_init(argv[0])) physfs_initialized = true;
//a bit of ugly syntax because of the need to consume the return type
atexit([]() {PHYSFS_deinit(); });
}
The crash apparently appears here
int __PHYSFS_platformGrabMutex(void *mutex)
{
EnterCriticalSection((LPCRITICAL_SECTION) mutex); // <-- here
return 1;
} /* __PHYSFS_platformGrabMutex */
Am I doing something wrong here ? Is this a problem of the library or even with my OS ? Was there something in the buildstep of PhysFS that I missed ?
Edit: I noticed that I read the return value of PHYSFS_init() wrong, however now I'm even more confused as PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) returns "no error", what is going on here ?
Apparently there is a bug in PhysFS regarding Windows 10. That prohibits the correct execution of PHYSFS_init()
changing line 578 of phsyfs_platform_windows.c to
rc = pGetDir(accessToken, NULL, &psize);
and a recompile of the library fixed the problem for me :/
https://hg.icculus.org/icculus/physfs/rev/ece6769c0676
https://discourse.libsdl.org/t/resolved-physfs-exception-thrown/25697/11

Unresolved overloaded function type when rewriting code c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm using ESP8266WiFiMesh library in my project which I run on nodeMCU. When the example provided by the library is in the Ardunino ino file it works well, but when I rewrite it into c++ cpp h files I run into some problems. In the Mesh::Mesh when I create an instance of ESP8266WiFiMesh class I provide two parameters: chipId and callback.
Error that I get when providing callback function (manageRequest)
<unresolved overloaded function type> to std::function<String(String)>
I'm struggling for a few days and I couldn't find any solution.
Here's the original example code that I use.
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFiMesh/examples/HelloMesh/HelloMesh.ino
Mesh.cpp :
#include "Mesh.h"
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMesh.h>
unsigned int request_i = 0;
unsigned int response_i = 0;
Mesh::Mesh() {
/* Create the mesh node object */
/* Here I'm getting Unresolved overloaded function when providing manageRequest function (callback) */
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest);
/* Create the utils node object */
utilsy = new Utils();
#ifdef DEBUG
Serial.println("Setting up mesh node...");
#endif
/* Initialize the mesh node */
mesh_node.begin();
}
/**
* Callback for when other nodes send you data
*
* #request The string received from another node in the mesh
* #response The string to send back to the other node
*/
String Mesh::manageRequest(String request) {
/* Split request */
String requestedTo = utilsy->getDelimitedValues(request, '.', 0);
String requestedFrom = utilsy->getDelimitedValues(request, '.', 1);
const char *cstr = requestedFrom.c_str();
String requestedMessage = utilsy->getDelimitedValues(request, '.', 2);
String requestedState = utilsy->getDelimitedValues(request, '.', 3);
#ifdef DEBUG
/* Print out received message */
Serial.print("Requested from: " + requestedFrom);
Serial.print("\tMessage: " + requestedMessage);
Serial.println("\tRequested state: " + requestedState);
#endif
/* return a string to send back */
char response[60];
//TODO should send back with same message and giving proper state [0,1] whether LED turned on/off
sprintf(response, "%s.%d.%d.%d", cstr, ESP.getChipId(), response_i++, 1);
return response;
}
The code does not work because your function is a class method, but you could use std::bind to get the appropriate result:
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(
ESP.getChipId(),
std::bind(&Mesh::manageRequest, this, std::placeholders::_1));

C++ how to pass vector of objects by reference into a function, then into next function? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm hoping somebody can provide some assistance here. Here is the relevant portion of the code I'm stuck on currently:
///////////////////////////////////////////////////////////////////////////////////////////////////
void matchBlobs(std::vector<Blob> &existingBlobs, std::vector<Blob> &currentFrameBlobs) {
for (auto &existingBlob : existingBlobs) {
existingBlob.blnCurrentMatchFoundOrNewBlob = false;
}
for (auto &currentFrameBlob : currentFrameBlobs) {
int intIndexOfLeastDistance = 0;
double dblLeastDistance = 1000000.0;
for (unsigned int i = 0; i < existingBlobs.size() - 1; i++) {
if (existingBlobs[i].blnStillBeingTracked == true) {
double dblDistance = distanceBetweenBlobs(currentFrameBlob, existingBlobs[i]);
if (dblDistance < dblLeastDistance) {
dblLeastDistance = dblDistance;
intIndexOfLeastDistance = i;
}
}
}
if (dblLeastDistance < currentFrameBlob.dblDiagonalSize * 1.5) {
addBlobToExistingBlobs(currentFrameBlob, existingBlobs, intIndexOfLeastDistance); // !!!! compiler error for 2nd arg on this line !!!!!!!
} else {
addNewBlob(currentFrameBlob, existingBlobs);
}
}
for (auto &existingBlob : existingBlobs) {
if (existingBlob.blnCurrentMatchFoundOrNewBlob == false) {
existingBlob.blnStillBeingTracked = false;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void addBlobToExistingBlobs(Blob &currentFrameBlob, std::vector<Blob> &existingBlobs, int &intIndex) {
existingBlobs[intIndex].contour = currentFrameBlob.contour;
existingBlobs[intIndex].boundingRect = currentFrameBlob.boundingRect;
existingBlobs[intIndex].ptCurrentCenter = currentFrameBlob.ptCurrentCenter;
existingBlobs[intIndex].dblDiagonalSize = currentFrameBlob.dblDiagonalSize;
existingBlobs[intIndex].dblAspectRatio = currentFrameBlob.dblAspectRatio;
existingBlobs[intIndex].vectorOfAllActualPoints.push_back(currentFrameBlob.ptCurrentCenter);
existingBlobs[intIndex].blnStillBeingTracked = true;
existingBlobs[intIndex].blnCurrentMatchFoundOrNewBlob = true;
}
As noted on the comment in the code, I'm getting a compiler error on this line:
addBlobToExistingBlobs(currentFrameBlob, existingBlobs, intIndexOfLeastDistance); // !!!! compiler error for 2nd arg on this line !!!!!!!
the error is:
Error C2664 'void addBlobToExistingBlobs(Blob &,Blob &,int &)': cannot convert argument 2 from 'std::vector<Blob,std::allocator<_Ty>>' to 'Blob &' ObjectTrackingCPP c:\users\cdahms\documents\visual studio 2015\projects\objecttrackingcpp2\objecttrackingcpp.cpp 186
Can anybody shed some light on what I'm doing wrong here? I can find plenty of C++ examples of passing one basic data type variable (int, double, etc.) by reference but I am unable to find any examples involving passing a vector of objects into one function, then into another function.
I'm using the compiler that ships with Visual Studio 2015 Community, with the default options chosen if that makes a difference.
I'm not sure what direction to go here, any assistance would be greatly appreciated.
It appears - from the error message - that the compiler knows your function as
void addBlobToExistingBlobs(Blob&, Blob&, int&);
whereas, in your implementation of
void matchBlobs(std::vector<Blob>&, std::vector<Blob>&);
a function with the name of addBlobToExistingBlobs is used, but with a different prototype, namely
void addBlobToExistingBlobs(Blob& ,std::vector<Blob>&, int&);
Have you checked that, somewhere in your code, you haven't a prototype for another addBlobToExistingBlobs function that gets the compiler confused ?

Pointers and enum in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm trying to rewrite my C++ code to C and got problems with comparising enum by pointers. Please take a look.
Enum:
enum state{TITLE,PLAY,LOST}
My function looks like that:
void ChangeState(int *state, int NewState)
{
state = NewState;
if (state == TITLE)
{
/* something */
}
else if (state == PLAY)
{
/* something2 */
}
else if (state == LOST)
{
/* something3 */
}
}
And when I try calling this function by:
ChangeState(&state, TITLE)
etc. it doesn't work correctly. Also when I put in my code:
if (state == TITLE)
{
/* instructions */
}
What is my mistake? Thanks from advance for your time.
You need to dereference the pointer (use *state) to read the value it points to
This means your code should change to
void ChangeState(int *state, int NewState)
{
*state = NewState;
if (*state == TITLE)
{
/* something */
}
else if (*state == PLAY)
{
/* something2 */
}
else if (*state == LOST)
{
/* something3 */
}
}
In addition to simonc answer, you can also change the if statements by a switch. Given the case (working with enums) is more appropiated.
void ChangeState(int *state, int NewState)
{
*state = NewState;
switch (*state)
{
case TITLE:
// ...
break;
case PLAY:
// ...
break;
case LOST:
// ...
break;
default: break;
}
}
What you did, its change the address of the pointer. What you would like to do is to change the value of the int that stored in that address(where the pointer points). So to correct the mistake you need to put a * before the pointer name.
Many programmers use prefixes to keep track of the level of indirection.
If you have a pointer-to-state, it should be named pState:
void ChangeState(int *pState, int NewState)
{
*pState = NewState;
// Error: This changed the POINTER, not the value referenced by the pointer.
// state = newState;
[....]