Error undefined reference. - Compile
Feb 18, 2016 at 10:11pm UTC
Hi All, I am getting an error for undefined reference. I am not sure what it could be as the compiler doesnt give me a line but only the program and the functions.
1 2 3
invoice_client.cpp:(.text+0x199): undefined reference to `invoice::set_partnum(std::string)'
invoice_client.cpp:(.text+0x1b8): undefined reference to `invoice::get_partnum()'
collect2: error: ld returned 1 exit status
here is my header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#ifndef invoice_h_
#define invoice_h_
#include <iostream>
#include <string>
class invoice
{
public :
invoice(std::string partNum,
std::string partDesc,
int reqQty,
double price);
invoice();
~invoice();
//----------------------------------------------------
//Qty
void qty(int req);
//----------------------------------------------------
// Get Partnum
const std::string get_partnum();
//----------------------------------------------------
// Get Partnum
const std::string get_partdesc();
//----------------------------------------------------
// Get Partnum
const int get_qty();
//----------------------------------------------------
// Get Partnum
const double get_price();
//----------------------------------------------------
// Set Partnum
void set_partnum(std::string sPartnum);
//----------------------------------------------------
// Set Partdesc
void set_partdesc(std::string sPartdesc);
//----------------------------------------------------
// Set Qty
void set_qty( int sqty);
//----------------------------------------------------
// Set price
void set_price( double sprice);
//----------------------------------------------------
//Invoice Amt
const double get_invoice() const ;
//----------------------------------------------------
//display string
const std::string asstring() const ;
private :
//----------------------------------------------------
//Part number
std::string m_partNum;
//----------------------------------------------------
//Part Description
std::string m_partDesc;
//----------------------------------------------------
//Price
double m_price;
//----------------------------------------------------
//Qty
int m_qty;
};
#endif
Definitions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include "invoice.h"
using namespace std;
//----------------------------------------------------
//Invoice Default
invoice::invoice(){
m_partNum = "0" ;
m_partDesc = "0" ;
m_qty = 0;
m_price = 0;
}
invoice::invoice(std::string partNum,
std::string partDesc,
int reqQty,
double price){
m_partNum = partNum;
m_partDesc = partDesc;
m_qty = reqQty;
m_price = reqQty;
}
invoice::~invoice(){
}
//----------------------------------------------------
//get balance
const double invoice::get_invoice() const {
return m_qty * m_price;
}
//----------------------------------------------------
// Set Partnum
void set_partnum(std::string sPartnum){
std::string m_partNum = sPartnum;
}
//----------------------------------------------------
// Set Partdesc
void set_partdesc(std::string sPartdesc){
std::string m_partDesc = sPartdesc;
}
//----------------------------------------------------
// Set Qty
void set_qty( int sqty){
int m_qty = sqty;
}
//----------------------------------------------------
// Set price
void set_price( double sprice){
double m_price = sprice;
}
//----------------------------------------------------
//display
const std::string invoice::asstring() const {
ostringstream oss;
oss << "Part# : " << m_partNum << "\n"
"Part Desc : " << m_partDesc << "\n"
"Qty : " << m_qty << "\n"
"Price : " << m_price;
return oss.str();
}
Program file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <string>
#include "invoice.h"
using namespace std;
std::string in_prtnum;
int main(){
//---------------------------------------------
//Define 2 Accounts
invoice inv1;
cout << inv1.asstring() << endl;
invoice inv2("DSK232" , "Screws" , 12, 21.10);
cout << inv2.asstring() << endl;
//*---------------------------------------------
//Set PartNum
cout << "Please provide a Part# to this unknown part: " << endl;
::in_prtnum;
cin >> ::in_prtnum;
inv1.set_partnum(in_prtnum);
cout << "How much would you like to deposit into ACCT: "
<< inv1.get_partnum();
return 0;
}
Last edited on Feb 18, 2016 at 10:13pm UTC
Feb 18, 2016 at 10:29pm UTC
Topic archived. No new replies allowed.