第一個函式
你在 C++ 要寫的第一個函式,或許也是你此生唯一需要的函式,因為你要寫一個會回傳關於生命、宇宙與一切的終極問題答案的函式。
你的工作環境已經載入 Rcpp。
本練習屬於課程
用 Rcpp 最佳化 R 程式碼
練習說明
撰寫一個 C++ 函式 the_answer(),不接受任何引數,並且一律回傳整數 42。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define the function the_answer()
cppFunction('
___ ___() {
return ___ ;
}
')
# Check the_answer() returns the integer 42
the_answer() == 42L