我已经检查过拼写错误多次我不明白我为什么会在主要时收到此错误。我正在创建一个新对象,并尝试使用单独的函数调用该对象,但收到未定义的引用错误。
我在编译时收到以下错误
/tmp/cceicIWu.o: In function `main':
RationalFractionTest.cpp:(.text+0xc9): undefined reference to `RationalFraction::displayFraction()'
collect2: ld returned 1 exit status
RationalFractionTest.cpp:
#include<iostream>
#include<iomanip>
using namespace std;
#include "RationalFraction.h"
#include "Program5.cpp"
//function main begins program execution
int main()
{
RationalFraction one(1,-2);
one.displayFraction();
}
RationalFraction.h:
#include<string>
using namespace std;
//RationalFraction class definition
class RationalFraction
{
public:
RationalFraction(int a, int b); //Constuctor
static RationalFraction add ( RationalFraction one, RationalFraction two);
static RationalFraction subtract ( RationalFraction one, RationalFraction two);
static RationalFraction multiply ( RationalFraction one, RationalFraction two);
static RationalFraction divide ( RationalFraction one, RationalFraction two);
void displayFraction(); // This will also reduce the fraction using GCD, and give decimal equivalent
private:
int top;
int bottom;
};
Program5.cpp:
RationalFraction::RationalFraction(int a, int b)
{
}
RationalFraction RationalFraction::add(RationalFraction one, RationalFraction two)
{
}
RationalFraction RationalFraction::subtract(RationalFraction one, RationalFraction two)
{
}
RationalFraction RationalFraction::multiply(RationalFraction one, RationalFraction two)
{
int newtop;
int newbottom;
newtop = one.top * two.top;
newbottom = one.bottom * two.bottom;
float result = float (newtop) / float (newbottom);
cout << "Fraction is " << newtop << "/" << newbottom << ". Which is decimal " << fixed << setw(5)
<< setprecision(4) << result << endl;
RationalFraction newRationalFraction(newtop, newbottom);
return newRationalFraction;
}
RationalFraction RationalFraction::divide(RationalFraction one, RationalFraction two)
{
}
void displayFraction()
{
cout<<"here";
}