I'm trying to create a Node.js C++ Addon that generates the Fibonacci sequence to compare its speed with a normal Node.js module, but I'm getting the error:
../hello.cc:16:16: error: array initializer must be an initializer list
Here's the code:
#include <node.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::Value;
using v8::Number;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
int next, first = 0, second = 0, c = 0, n = args[0]->NumberValue();
Local<Number> arr[] = new Local<Number>[n];
for (; c < n; c++) {
if ( c <= 1 ) next = c;
else {
next = first + second;
first = second;
second = next;
}
arr[c] = Number::New(isolate, next);
}
args.GetReturnValue().Set(arr);
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "fib", Method);
}
NODE_MODULE(addon, init)
}
Why is this happening?
via Bennett
No comments:
Post a Comment