编译时报错“ undefined reference to”

报错

写了一段小程序,报错“exception.cpp:(.text+0x28): undefined reference to `Sales_item::setPrice(double)“

程序就算c++ prime中得测试程序:

程序代码

//*********Sales_Item.h

#ifndef SALES_H
#define SALES_H

#include 
using namespace std;
class Sales_item
{
        public:
                Sales_item();
                Sales_item(double p,double q);
                inline double getPrice();
                inline double getQuatity();
                inline void setPrice(double p);
                void setQuatity(double q);
                double operator + (Sales_item& s2);
        private:
                string Id;
                double price;
                double quatity;
};

#endif

//********Sales_Item.cpp

 #include "Sales_item.h"
  2 #include
  3 
  4 //using namespace std;
  5 
  6 Sales_item::Sales_item(){}
  7 
  8 Sales_item::Sales_item(double p, double q):price(p),quatity(q){}
  9 
 10 inline double Sales_item::getPrice()
 11 {
 12         return price;
 13 }
 14 inline  double Sales_item::getQuatity()
 15 {
 16         return quatity;
 17 }
 18 inline  void Sales_item::setPrice(double p)
 19 {
 20         price = p;
 21 }
 22 void Sales_item::setQuatity(double q)
 23 {
         quatity = q;
 25 }
 26 
 27  double Sales_item::operator +(Sales_item& s2)
 28 {
 29         return this->price*this->quatity+s2.getPrice()*s2.getQuatity();
 30 }

//********* exception.cpp

#include
#include
#include "Sales_item.h"

//using namespace std;

int main()
{
        Sales_item sItem;
        sItem.setPrice(10.1);
        sItem.setQuatity(20);
        Sales_item s2(1,100);
        double tmpPrice = sItem.getPrice();
        double tmpQuatity = sItem.getQuatity();
        cout<<"the Item price is :"<the Item price is :10.1
the Item price is :20
the sum is :(10.1*20)+(1*100)=302

你可能感兴趣的:(c++)