Converting 'float' to 'float*'

Hello all,

I am getting an error in this code and at this point I have no idea what I am doing wrong.

On line 64 It returens an error “error: cannot convert ‘float’ to ‘float*’ for argument ‘2’ to ‘int getNumIntersects(int, float*, float*, float*, float, float, float)’”

What does this even mean? What have I done wrong?

I am brand new to functions and just trying to learn how they work.

    #include "ofApp.h"

float getDistance(float x1, float y1, float x2, float y2){
    float deltaX = x2-x1;
    float deltaY = y2-y1;
    float distance = sqrt(deltaX*deltaX+deltaY*deltaY);
    return distance;
}

int intersects(float cx1, float cy1, float cx2, float cy2, float r){
    int intersect = 0;
    if (getDistance(cx1,cy1,cx2,cy2) <=  r){
        intersect += 1;
    }
    return intersect;
}

int getNumIntersects(int n, float cxArray[], float cyArray[], float rArray[], float cx, float cy, float r){
int i;
int num = 0;
for(i = 0; i < n ; i++){
    if(intersects(cxArray[i],cyArray[i],cx,cy,r) == 1){
        num += 1;
    }
}
}


int r = ofRandom(100);
float cxArray[10000];
float cyArray[10000];
float rArray[10000];


int screenX = 1000;
int screenY = 1000;

int cx = ofRandom(screenX);
int cy = ofRandom(screenY);

//--------------------------------------------------------------
void ofApp::setup(){









}

//--------------------------------------------------------------
void ofApp::update(){
    int i;
    int num = 0;
    int n = 10000;

    float r = ofRandom(100);
    float cx = ofRandom(screenX);
    float cy = ofRandom(screenY);
    for(i = 0 ; i < n ; i++)
        if(getNumIntersects(n,cxArray[i],cyArray[i],rArray[i],cx,cy,r) = 0 ){
            cxArray[i] = cx;
            cyArray[i] = cy;
            rArray[i] = r;
            num += 1;
        }
ofCircle(cxArray[num],cyArray[num],rArray[num]);

hello,

You try to pass a value of an array at index i where function needs an array of float, which is considered a pointer. You usually don’t pass the array itself but the pointer.

And you may need a double “=” in the if condition

 if(getNumIntersects(n,cxArray[i],cyArray[i],rArray[i],cx,cy,r) == 0 )
1 Like

So pointers are the key to this… Which I have learned nothing about thus far. Guess that’s what I will be reading about next.

Thanks