From a script language I will call functions from a DLL written in C++. In the DLL I want to initialize an array of double floats. And then use these values every time I call a function from that DLL. Is this possible?
I cannot declare this variable in the script language because it does not support doubles.
I started to work with DLLs and DEVC++ just days ago. So I just don't know how to do this, or even google it. I tried Gloabal vars and Static vars but I had no luck. If you point me to the right article, or even tell me what is the terminology for it, then I guess I can do it.
My thinking:
1) I want to call the DLL function init_vars(). This will initialize an array of double floats.
2) I want to call func1() and func2() DLL functions. Those will use the array.
Simple, I just don't know how to declare stuff to do it.
auto get_array()
-> std::vector<double> &
{
static std::vector<double> v {0.0, 3.14, 10.0, 11.2}; //only initialized once
return v;
};
void func1()
{
auto &array = get_array();
//...
}
void func2()
{
auto &array = get_array();
//...
}
By the way, some versions of DevC++ are terribly outdated and should not be used - check out this article and consider switching to another IDE: http://www.cplusplus.com/articles/36vU7k9E/
I tried to understand your code and use it. It seems that the std::vector notation is about the Standard Vector. Since I am a beginner, I would prefer the "normal" array. So I am trying to rewrite the code, use memory allocation etc.
If it is easy for you, would you mind writing this in more simple terms?
You should have learned about std::vector before learning about plain arrays. Plain arrays are far more complicated than std::vector and I try to avoid using them as much as possible.