问题描述:

This question already has an answer here:

  • What is an undefined reference/unresolved external symbol error and how do I fix it?

    25 answers

网友答案:

The declaration and the definition don't match.

double computeArea(int, int, int);

double computeArea(int *X, int *Y, int points)

Change the declaration to:

double computeArea(int *, int *, int);

Change the way you call it. Instead of

for (int i=0; i<12; i++)
{
    computeArea(xvalue[i], yvalue[i], 12);
}

use

double area = computeArea(xvalue, yvalue, 12);

To print the area, instead of

cout << "Your area is: " << computeArea() << endl;

use

cout << "Your area is: " << area << endl;

EDIT

You haven't initialized area to 0. That needs to be fixed.

Your formula you are using to compute the area is incorrect. It needs be

    area += (X[j]*Y[i] - X[i]*Y[j]);

See http://mathworld.wolfram.com/PolygonArea.html.

网友答案:

This is how you have called your function:

    cout << "Your area is: " << computeArea() << endl;

This is what your function prototype is:

double computeArea(int *X, int *Y, int points)

As you can see, it expects 3 parameters, and you are passing none.

Again, another prototype:

    double computeArea(int, int, int);

The first one uses pointers, the second one uses normal ints.

Hence the warning.

相关阅读:
Top