| gugge444 (7) | |
|
I created a 1d array using the trick double* x = new double[var]; which seems to be the only way of creating an array with a variable size. However, I now need to use the parts of x --> (x[1], x[2], ..., x[i]) in a function that requires a double input, and I cannot do that with a double*. Is there a way of solving this without entering the source code and trying to change the input method, or rather, is there a way of turning a double* to a double, or better yet, create a double with a variable input? Thanks in advance. | |
|
|
|
| EssGeEich (681) | |||
|
When a function takes a double, you can only give it a single double, not more than one at once. For examples:
| |||
|
|
|||
| gugge444 (7) | |
|
Thank you, that is accurate, but not what I was asking. I know I formulated the question poorly, sorry about that. What I meant to ask is: when I attempt to make the size of a double[] using a variable, the error: expression must have a constant valueappears. The way to bypass this is to make the double[] into a double*[]. However, this type is not compatible with a function I want to run it through. So my question is: do I have to rewrite the function, or is there a way of bypassing this error? | |
|
|
|
| EssGeEich (681) | |||
|
Sorry but, Have you tried passing it normally? Let me explain you this:
If yet I didn't answer correctly, could you make an example, posting a little code snip maybe? | |||
|
Last edited on
|
|||
| maeriden (228) | ||||||||
Dereference it
Not sure what you're asking here
If your function works with a single double at a time, just pass it using an index
I'm guessing you just started dealing with pointers. If you need help understanding what's going on feel free to ask | ||||||||
|
|
||||||||