C ++ [Ошибка компоновщика] неопределенная ссылка на `executeComputation (char, double) '

0

У меня очень простой проект для начинающего класса программирования. Я просмотрел каждый вопрос о переполнении стека, связанный с этой ошибкой, и никто из них не помог моей проблеме, поэтому я решил спросить себя.

lab5.cpp

#include <cstdlib>
#include <iostream>
#include <math.h>
#include "shape.h"

using namespace std;
int main()
{
    char shape = '0';
    char compType = '0';
    double radius = 0.0;
    double height = 0.0;
    shape = inputShape();

    while (shape != QUIT)  
    {
        switch(shape)
        {
            case SPHERE:
                inputDimension(radius);
                compType = inputCompType(); 
                performComputation(compType, radius);
                break;
            case CYLINDER:
            case CONE:
                inputDimension(radius, height);
                compType = inputCompType(); 
                performComputation(shape, compType, radius, height);
                break;
        }
    }
    cout << "GoodBye!";
    system("PAUSE");
    return 0;           

}
char inputShape()
{
char c = '0';
cout << "Select a shape (1) Sphere, (2) Cylinder, (3) Cone (Q) Quit: ";
cin >> c;
return c;
}
void inputDimension(double& r)
{
cout << "Input a Radius: ";
cin >> r;
}
void inputDimension(double& r, double& h)
{
cout << "Input a Radius: ";
cin >> r;
cout << "Input a Height: ";
cin >> h;
}
char inputCompType()
{
char c = '0';
cout << "Select a Computation (1) Volume (2) Surface Area: ";
cin >> c;
return c;
}
void perfomComputation(char c, double d)
{
if(c == SURFACE_AREA)
{
    cout << "The surface area of the Sphere is: " << sphere_surface_area(d);
} 
else if (c == VOLUME)
{
    cout << "the volume of the Sphere is: " << sphere_volume(d);
}
}
void performComputation(char b, char c, double d, double e)
{
if (b == CYLINDER)
{
    if(c == SURFACE_AREA)
    {
        cout << "the surface area of the Cylinder is: " <<cylinder_surface_area(d,e);
    }
    else if (c == VOLUME)
    {
        cout << "the volume of the Cylinder is: " << cylinder_volume(d,e);
    }
}
else if (b == CONE)
{
    if (c == SURFACE_AREA)
    {
        cout << "the surface area of the Cone is: " << cone_surface_area(d,e);
    }
    else if (c == VOLUME)
    {
        cout << "the volume of the Cone is: " << cone_volume(d,e);
    }
}
}
double sphere_surface_area(double r)
{
return (4.0) * PI * pow(r,2);
}
double sphere_volume(double r)
{
return (4.0/3.0) * PI * pow(r,3);
}
double cylinder_surface_area(double r, double h)
{
return ((2.0) * PI * pow(r,2))+((2.0) * PI * r * h);
}
double cylinder_volume(double r, double h)
{
return (PI * pow(r,2) * h);
}
double cone_surface_area(double r, double h)
{
return (PI*pow(r,2)) +((PI*r)*sqrt((pow(r,2) + pow(h,2))));
}
double cone_volume(double r, double h)
{
return (1.0/3.0)*(PI * pow(r,2) * h);
}

shape.h

#include <iomanip>
#include <cstdlib>
#include <iostream>
//constant declarations
const double PI = 3.141593;
const char SPHERE = '1';
const char CYLINDER = '2';
const char CONE = '3';
const char QUIT = 'Q';
const char VOLUME = '1';
const char SURFACE_AREA = '2';
//function declarations
char inputShape();
void inputDimension(double&);
void inputDimension(double&, double&);
char inputCompType();
void performComputation(char, char, double, double);
void performComputation(char, double);
double sphere_volume(double);
double sphere_surface_area(double);
double cylinder_volume(double, double);
double cylinder_surface_area(double, double);
double cone_volume(double, double);
double cone_surface_area(double, double);

мои ошибки:

[Linker error] undefined reference to 'performComputation(char, double)'
ld returned 1 exit status
C:\Users\AdminM\Documents\Cpp\Lab5\Makefile.win [Build Error]  [Lab5.exe] Error 1 
  • 0
    Показать точную команду компиляции. Порядок аргументов в g++ имеет большое значение.
Теги:
linker
compilation

3 ответа

1
Лучший ответ

в lab5.cpp

void perfomComput (char c, double d) {}

Вы пропустили букву "r" в имени функции. Вот почему компоновщик не может найти реализацию функции executeComput, объявленной в файле заголовка.

  • 0
    теперь я чувствую себя абсолютно глупо, потому что я переписал эту строку около 5 раз.
0

Я вижу void performComputation(char, double); в .h файле, но не вижу его в .cpp Я думаю, что линкер также задается вопросом, где он, по крайней мере, с тех пор, как вы используете его в своем коде.

Изменение: Да, я просто использовал текстовый поиск в своем браузере :)

0

В void perfomComputation(char c, double d) в lab5.cpp отсутствует символ орфографии - r.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню