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

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

Related

`Rcpp::wrap` and `Rcpp::as` for external classes that use Rcpp namespace classes

How can Rcpp::wrap and Rcpp::as methods be written for classes that contain an Rcpp class?
For example, the following .cpp file compiles using sourceCpp():
#include <Rcpp.h>
namespace Rcpp {
class myVector {
public:
NumericVector data;
myVector(NumericVector v) : data(v) {};
};
template <> myVector as(SEXP v) {
return myVector(v);
}
template <> SEXP wrap(const myVector& v) {
return v.data;
}
}
//[[Rcpp::export]]
Rcpp::myVector test(Rcpp::myVector& x){
return x;
}
In this example, we create a vector that is comprised simply of a single Rcpp class (NumericVector) and an Rcpp::as and Rcpp::wrap method so that it can be used as an argument in any exported function.
However, the code does not pass when creating an Rcpp package as follows:
Rstudio -> New Project -> New Directory -> R package using Rcpp
Copy above script into new file, test.cpp
Build -> Install and Restart
There are no complaints about the test.cpp but there are complaints in src/RcppExports.cpp. Here's the relevant function:
// test
Rcpp::myVector test(Rcpp::myVector& x);
RcppExport SEXP _test_test(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::myVector& >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(test(x));
return rcpp_result_gen;
END_RCPP
}
The errors are:
Line 19: `myVector` does not name a type;
Line 24: `myVector` was not declared in this scope
... template argument 1 invalid, qualified-id in declaration, 'x' not declared, 'test' not declared... side-effects of above two errors.
I do know how to write Rcpp::as and Rcpp::wrap for classes that do NOT contain Rcpp classes (templated case, general case):
#include <RcppCommon.h>
Forward-declaration of class, may depend on C++ libraries (not Rcpp.h)
#include <Rcpp.h>
Unfortunately, Rcpp::myVec requires Rcpp.h and thus cannot be declared prior to including Rcpp.h.
Can external classes containing Rcpp classes make use of Rcpp::wrap and Rcpp::as? If so, is there any precedent I can view for details? I haven't found any despite quite a bit of searching, or maybe I'm overlooking something very simple.

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.

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";

RCpp long long unsigned int error issue

I am a newbie to Rcpp and C++. I am trying to convert the following R code into RCpp.
library (compiler)
robzscore<-cmpfun(function(x) {
byec <- sum(!is.na(x))
byer <- rank(x, na.last="keep", ties.method="average") - 0.5
as.data.frame(suppressWarnings(qnorm(byer/byec)), row.names=NULL)
})
I am struggling with writing the syntax for the part where i need to get the ranks. For example, this is what I wrote (in a separate cpp file that I am compiling using sourceCpp) based on other codes I found on SO as an equivalent of the rank(x,...) function in R assuming there are no NAs (and not handling ties):
#include <Rcpp.h>
#include <algorithm>
#include <iostream>
using namespace Rcpp;
template <typename T>
std::vector<size_t> sort_indexes(const std::vector<T> &v) {
// initialize original index locations
std::vector<size_t> idx(v.size());
for (size_t i=0; i!=idx.size();++i) idx[i]=i;
// sort indexes based on comparing values in v
std::sort(idx.begin(),idx.end(),[&v](size_t i1, size_t i2) {return v[i1]<v[i2];});
// return the values
return idx;
}
// [[Rcpp::export]]
NumericVector do_rank(NumericVector x) {
std::vector<float> y=as<std::vector<float> >(x);
return wrap(sort_indexes(y));
}
The error is get are:
lambda expressions only available with -std=c++0x or -std=gnu++0x [enabled by default] - followed by - no matching function for call to 'sort(std::vector<long long unsigned int>::iterator, std::vector<long long unsigned int>::interator, sort_indexes(const std::vector<T> &) [ with T=float]::<lambda(long long unsigned int, long long u
nsigned int)>)' at the place where my code says std::sort(idx.begin(),...).
~/R/win-library/3.0/Rcpp/include/Rcpp/internal/wrap.h : invalid conversion from 'long long unsigned int' to 'SEXP' [-fpermissive].
I suspect the main issue with some error I made in the syntax I used to handle Rcpp (converting Rcpp to C++ data structure or vice versa).
Can someone help me interpret the errors and/or what could be the right way?
Thanks,

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