[問題] cannot appear in a constant-expression

看板C_and_CPP作者 (天)時間8年前 (2017/03/12 17:15), 8年前編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/5 (看更多)
開發平台(Platform): (Ex: Win10, Linux, ...) windows 10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) gcc 4.9.3 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我是用Rcpp,我一直沒想通為什麼 而且google也看不太懂,自己C++功力沒有很深Orz Rcpp::NumericVector 這個object有下面這個method: inline int sexp_type() const { return TYPEOF( static_cast<const Class&>(*this) ) ; } 我想用sexp_type回傳的int去得到Rcpp::NumericVector的type (double) 但是會出現 // error: 'RTYPE1' cannot appear in a constant-expression 想問我哪裏寫錯了 x是 Rcpp::NumericVector 1. sexp_type const int RTYPE1 = x.sexp_type(); typedef typename Rcpp::traits::storage_type< RTYPE1 >::type type; // error: 'RTYPE1' cannot appear in a constant-expression 2. const int => PASS const int RTYPE2 = 14; typedef typename Rcpp::traits::storage_type< RTYPE2 >::type type; // PASS Rcpp::traits::storage_type在這裡: https://goo.gl/N7Wb82 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.233.49.87 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1489310142.A.AE6.html ※ 編輯: celestialgod (36.233.49.87), 03/12/2017 17:37:01

03/12 19:43, , 1F
RTYPE1的值不是在compile time得出,是要怎麼套進temp
03/12 19:43, 1F

03/12 19:43, , 2F
late
03/12 19:43, 2F
文章代碼(AID): #1OnH6-hc (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1OnH6-hc (C_and_CPP)