第一个函数
您在 C++ 中要编写的第一个函数,很可能也是您唯一需要的函数,因为您将编写一个函数,用来返回关于生命、宇宙以及一切的终极问题的答案。
Rcpp 已在您的工作空间中加载。
本练习是课程的一部分
用 Rcpp 优化 R 代码
练习说明
编写一个 C++ 函数 the_answer(),不接收任何参数,并且始终返回 int 42。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Define the function the_answer()
cppFunction('
___ ___() {
return ___ ;
}
')
# Check the_answer() returns the integer 42
the_answer() == 42L