cannot understand exc_bad_access(code=1,address=0x0)

I'm trying to use the conjugate method in the book Numerical Recipes, 3rd Ed and I'm new to Cpp. When testing this method, I encounter a warning of "Thread 1:exc_bad_access (code=1,address=0x0). But I don't know what's wrong. Below is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "nr3.h" 
#include "mins_ndim.h"
#include "mins.h"
#include <iostream>


int main() {
    
    struct Funcd {
        Doub operator() (VecDoub_I &x)
        {
            return x[0]*x[0]+x[1]*x[1];
        }
        void df(VecDoub_I &x, VecDoub_O &deriv)
        {
            deriv[0]=2.0*x[0];
            deriv[1]=2.0*x[1];
        }
    };
    
    Funcd funcd;
    Frprmn<Funcd> frprmn(funcd);
    VecDoub p;
    p[0]=1;
    p[1]=1;
    p=frprmn.minimize(p);
    
    
}

Topic archived. No new replies allowed.