Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Constexpr doubt :/

$
0
0
I may have got this wrong, but I thought that stuff marked with the keyword constexpr had to be known at compile time. Then why in my example below, where I pass to the constexpr function a value that is only know at run time, I don't get any errors?! size_t fib(size_t n) { if (n <= 1) { return 1; } return fib(n - 1) + fib(n - 2); } constexpr size_t fib_constexpr(size_t n) { if (n <= 1) { return 1; } return fib(n - 1) + fib(n - 2); } int main() { int n; cin >> n; cout << fib(n) << endl; cout << fib_constexpr(n) << endl; return 0; }

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>