SamuelNLP
SamuelNLP

Reputation: 4136

Call a function inside a function

What's wrong with this functions definitions? I've created this two functions and the second one calls the first one, so what i want is, depending on the if in the first one, the calling of AlignCamera(); will change what happens in AlignXAXis();

void AlignCamera();
        {
        double cx = ox+(0.5*(xmax-xmin))*sx;
        double cy = oy+(0.5*(ymax-ymin))*sy;
        double cz = oz+(0.5*(zmax-zmin))*sz;
        int vx=0;
        int vy=0;
        int vz=0;
        int nx=0;
        int ny=0;
        int nz=0;
        int iaxis = current_widget->GetPlaneOrientation();

        if (iaxis == 0)
        {
            vz = -1;
            nx = ox + xmax*sx;
            cx = ox + 256*sx;
            }
        else if (iaxis == 1)
        {
            vz = -1;
            ny = oy + ymax*sy;
            cy = oy + 512*sy;
            }
        else
        {
            vy = 1;
            nz = oz +zmax*sz;
            cz = oz + 64*sz;
            }
        int px = cx+nx*2;
        int py = cy+ny*2;
        int pz = cz+nz*3;

        vtkCamera *camera=ren->GetActiveCamera();
        camera->SetViewUp(vx, vy, vz);
        camera->SetFocalPoint(cx, cy, cz);
        camera->SetPosition(px, py, pz);
        camera->OrthogonalizeViewUp();
        ren->ResetCameraClippingRange();
        renWin->Render();
    }

// Define the action of AlignXAxis
void AlignXAxis();
        {
        int slice_number;
        int po = planeX->GetPlaneOrientation();
        if (po == 3)
        {
            planeX->SetPlaneOrientationToXAxes();
            slice_number = (xmax-xmin)/2;
            planeX->SetSliceIndex(slice_number);
        }
        else
        {
            slice_number = planeX->GetSliceIndex();
        }

        current_widget= planeX;
        ui->horizontalScrollBar->setValue(slice_number);
        ui->horizontalScrollBar->setMinimum(xmin);
        ui->horizontalScrollBar->setMaximum(xmax);
        AlignCamera();
    }

the variables needed are defined before it, such as ox, oy, oz....

When i run it it says undefined reference to `AlignCamera()' or 'AlignXAxis()'.

Upvotes: 0

Views: 141

Answers (2)

piokuc
piokuc

Reputation: 26164

Remove the semicolons, so:

void AlignCamera();
    {
     ...
    }

becomes

void AlignCamera()
    {
     ...
    }

Upvotes: 2

ATaylor
ATaylor

Reputation: 2598

void AlignCamera();  //This is merely a prototype, not a declaration.

Remove the Semicolon, or create a declaration afterwards.

void AlignCamera();  //Prototype
void AlignCamera() { //Declaration
    //Do Stuff
}

The same applies for the other function. Remove that semicolon.

Upvotes: 3

Related Questions