简体   繁体   中英

sourceCpp() fail to source this file

when compiling this file, warn "invalid conversion ... const int". Can someone tell what is wrong and how to fixit. thanks.

#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
IntegerVector ats(SEXP p, SEXP rolsd, SEXP sig, SEXP b)
{
  Rcpp::NumericVector loc_p(p);
  Rcpp::NumericVector loc_rolsd(rolsd);
  Rcpp::IntegerVector signal(sig);
  int n=loc_p.size();
  int m=signal.size();
  float bb = Rcpp::as<float>(b);
  Rcpp::IntegerVector result[m];
  for(int j=0;j<m;j++)
  { 
    int i=0;
    float  ma=loc_p[j];
    while(loc_p[i+signal[j]] >= (1-loc_rolsd[i+signal[j]]*bb)*ma & i<=n-signal[j])
    {
      i=i+1;
      if(ma < loc_p[i+signal[j]]) ma = loc_p[i+signal[j]];
    }
    result[j]=i;
  }
  return result;
}

Please check your while statement.

while(((loc_p[i+signal[j]]) >= ((1-loc_rolsd[i+signal[j]]*bb)*ma)) && (i<=n-signal[j]))
    {
      i=i+1;
      if(ma < loc_p[i+signal[j]])
         ma = loc_p[i+signal[j]];
    }

And I think you have to check this statement too.

Rcpp::IntegerVector result[m];

While declaration array need Constant Value So you need to declare as

Rcpp::IntegerVector result[10]; // where m should be any int const value Rcpp::IntegerVector result[10]; // where m should be any int const value Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM