作者celestialgod (天)
看板C_and_CPP
标题[问题] cannot appear in a constant-expression
时间Sun Mar 12 17:15:37 2017
开发平台(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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1489310142.A.AE6.html
※ 编辑: celestialgod (36.233.49.87), 03/12/2017 17:37:01
1F:推 loveflames: RTYPE1的值不是在compile time得出,是要怎麽套进temp 03/12 19:43
2F:→ loveflames: late 03/12 19:43