non declared identifier in c++ - global-variables

i am creating a global variable of a class in a header file in which all global variables are created. And the i define it in the main.
Here's the example:
in listVariables.h:
#include <vector>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <locale>
using namespace std;
#include "dbSlice.h"
extern vector<dbSlice_str> dbSlice;//from dbSlice header i am creating the global variable
In main.cpp i define the variable:
#include "listVariables.h"
vector<dbSlice_str> dbSlice;
in dbSlice.cpp i create a global function that creates a variable and add it to the vector:
#include "dbSlice.h"
#include "listVariables.h"
#include "listFunctions.h"//where i declare the init_slice() function
void init_slice()
{
dbSlice.push_back(dbSlice_str());
dbSlice_str* slice;
slice = new dbSlice_str();
slice->name = "embb";
slice->connected_users = 0;
slice->client_weight = 100; //100% des ressources
slice->priority = 10;
slice->SST = 0;
slice->preemt = false;
slice->slice_ratio = 100;
dbSlice.push_back(*slice);
}
Then i call the init_slice() function in the main().
It's giving me errors relating to the decleration of the variable which i am not able to solve:
Error C2065 'dbSlice_str' : iidentifier not declared in listVariables.h
Error C2923 'std::vector' : 'dbSlice_str 'is not a valid model argument for the' _Ty 'parameter in listVAriables.h
Error C3203 'allocator' : non-specialized model class cannot be used as a model argument for the model parameter '_Alloc'; expected real type in listVariables.h
Error C2663 'std::vector<_Ty,_Alloc>::push_back' : 2 overloads have no conversion allowed for the 'this' pointer in dbSlice.cpp
Could you please help me with this?
thank you.

Related

Vector error error: '__uninitialized_copy_a' is not a member of 'std'

i cant include Vector
`#include
#include
#include
using namespace std;
int main(){
return 0;
}
if i include vector, the program display it
error: '__uninitialized_copy_a' is not a member of 'std'
and show me a lot o files about vector, i already instaled it and reinstal, repair, i cant include a vector

Rcpp function default values in header file

I whant to specify default values for my Rcpp function arguments in header file. So I have header file foo.h:
#ifndef foo_H
#define foo_H
#include <Rcpp.h>
int foo(int k = 3);
#endif
I also have foo.cpp file:
#include "foo.h"
#include <Rcpp.h>
using namespace Rcpp;
//'Some description
//'
//' #export
// [[Rcpp::export]]
int foo(int k)
{
return(k);
}
I compile the package and use this function from R:
foo()
Then I get error "argument "k" is missing, with no default" while I am expecting 3 to be returned.
Please help we to figure out how to define Rcpp default values in header file.
Will be very greatfull for help!
P.S. I need to specify default values in header file only and not any other place. It is clear to me how to specify default values in .cpp but I need to specify them in .h.

Problem with using vtkImagePlaneWidget & vtkPOpenFOAMReader

enter image description here
I used vtkPOpenFOAMReader to read *.foam.
And also I used vtkImagePlaneWidget to read dicom data to 3D show.
Everything is okay, I got the result. But there is a critical issue.
I can see foam data is perfect.
But if add only this code<(1)>, a broken line appears on foam data.
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
using namespace std;
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkImagePlaneWidget> planeWidget = vtkSmartPointer<vtkImagePlaneWidget>::New();/*(1)*/
vtkSmartPointer<vtkPOpenFOAMReader>openFOAMReader = vtkSmartPointer<vtkPOpenFOAMReader>::New();
openFOAMReader->SetCaseType(0);
openFOAMReader->SetFileName("./PatientA/ffr.foam");
openFOAMReader->CreateCellToPointOn();
openFOAMReader->EnableAllCellArrays();
openFOAMReader->DecomposePolyhedraOn();
openFOAMReader->Update();
vtkSmartPointer< vtkGeometryFilter> filter = vtkSmartPointer<vtkGeometryFilter>::New();
filter->SetInputConnection(openFOAMReader->GetOutputPort());
vtkSmartPointer<vtkCompositePolyDataMapper2> mapper = vtkSmartPointer<vtkCompositePolyDataMapper2>::New();
mapper->SetInputConnection(filter->GetOutputPort());
mapper->SetScalarModeToUsePointFieldData();
mapper->SelectColorArray("p");
mapper->SetScalarRange(-10, 50);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
renWin->Render();
iren->Start();
return true;
}
So why it is happened? It's a very critical issue for me.

atmel studio ifndef compilation error

Hi imy project recognises double definitions of variables that do not exist 2 times. I suppose that some how by changing my code and recompiling it stucks.
LedMatrix7219.cpp.o:(.data.Alphaletter+0x0): multiple definition of `Alphaletter' LedController.cpp.o:(.data.Alphaletter+0x0): first
defined here
LedMatrix7219.cpp.o:In function `loop'
LedController.cpp.o:(.bss.arr+0x0): first defined here
LedMatrix7219.cpp.o:In function `loop'
LedController.cpp.o:(.data.Alphaletter2+0x0): first defined here
collect2.exe*:error: ld returned 1 exit status
I have a class LedController and a header LettersDefinition.h
All the headers start like this:
I am including a struct and an enum from the LetterDefinition.h to the LedController so at the header i need to include the LetterDefinition.h in order to make a certain struck.
#ifndef __LEDCONTROLLER_H__
#define __LEDCONTROLLER_H__
#include <Arduino.h>
#include "LettersDefinition.h"
LetterStruct finalText;
String theText="Test";
void test();
//it does some extra staff
#endif //__LEDCONTROLLER_H__
And the header of the letter definition.
#ifndef LETTERSDEFINITION_H_
#define LETTERSDEFINITION_H_
#include "arduino.h"
#include <avr/pgmspace.h>
struct LetterStruct{
lettersEnum name;
uint8_t size;
uint8_t columnSize[5];
uint8_t data[18];
}Alphaletter;
#endif /* LETTERSDEFINITION_H_ */
And from my main .ide file i call the test function of the Ledcontroller i a get the error you see above. The test fuction just checks the LetterStruct.name variable nothing more.
My .ide is something like:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
#include "LedController.h"
LedController controller;
void setup()
{
//irrelevant inits
}
void loop()
{
controller.test();
delay(2000);
}
If i delete the #include "LettersDefinition.h" from the LedController.h this error gives its place to an error that the LetterStruct is not defined in the LedController.h which is normal since i have to add the LettersDefinition.h in order to be defined.
Your problem originates that you "define" variables in header files. This in general will lead to the multiple definition problem and is not standard design.
The model you need to follow is to define once in a source file:
//some.cpp
// this is define
int variableX = 5;
And declare in the header file:
//some.h
// this is declare
extern int variableX;
Every other source file that includes the header just processes the "extern" line, which says roughly "there is an int variableX that will exist in the final program". The compiler runs over every .cpp .c file and creates a module. For the some.cpp that defines the variable, it will create the variableX. All the other .cpp files will just have the extern reference which is a placeholder. The linker will resolve those placeholders when it combines all the modules together.
In your specific case, this means changing:
// .h file should only be externs:
extern LetterStruct finalText;
extern String theText;
// .cpp file contains definitions
LetterStruct finalText;
String theText="Test";

Borland C++ Builder 6 - E2316 'vector' is not a member of 'std'

Reasonably new to c++, I'm trying to use vectors in my application.
I am using
#include <vector>
in the header file, but when I compile it fails on this line:
std::vector<Shot> shot_list;
Noting the error E2316 'vector' is not a member of 'std'
If I then remove std::, It results in the Undefined symbol 'vector' compiler error message. Really at a loss with this one. Had no issues using
std::list<Shot> shot_list;
prior to using vectors.
Here is a simple example that fails to comile:
//---------------------------------------------------------------------------
#ifndef testclassH
#define testclassH
//---------------------------------------------------------------------------
#include <vector>
class TestClass {
private:
std::vector<int> testVect(1); // removing std:: and adding using namespace std; below the include for the vector it still fails to compile;
};
#endif
To me I don't see any difference between this and This Example
Without clarifying which namespace that the vector is in, you can not use "vector" by itself. (using namespace std;) Maybe you can paste your related code for more spesific help.
Edit:
You can not initialize the vector in the .h. You need to do it in .cpp maybe using the resize() function of the vector. This can be an option for you (using the constructor of the class):
#ifndef testclassH
#define testclassH
//---------------------------------------------------------------------------
#include <vector>
class TestClass {
private:
std::vector<int> testVect;
public:
TestClass()
{
testVect.resize(4);
}
};
#endif
The simple example that you have given compiles if you make the change.

Resources