Another C++ Problem

Discussion in 'Computing, Science, and Technology' started by mattym, Dec 10, 2009.

  1. mattym

    mattym New Member

    Joined:
    Sep 22, 2007
    Messages:
    786
    Likes Received:
    3
    Device:
    iPhone 4 (Black)
    Ok i hate having made the switch from Java to C++, im still getting used to it.
    Here is my problem. I created a class and header file for a project im working on.
    Im gonna post the header, source, and test file for it. My problem is that my compiler (g++ on a linux system, i have to use it) wont compile the test file it keeps returning "undefined reference to" for all the class functions.

    Header
    Code:
    #ifndef INVOICE_H
    #define INVOICE_H
    
    //Class Definition
    
    #include <string>
    using namespace std;
    
    class Invoice
    {
    public:
    	Invoice();
    
    	void setPartNum(string);
    	string getPartNum();
    
    	void setPartDesc(string);
    	string getPartDesc();
    
    	void setPartAmt(int);
    	int getPartAmt();
    
    	void setPartPrice(int);
    	int getPartPrice();
    
    private:
    	int price;
    	int amount;
    	string description;
    	string partNumber;
    };
    
    #endif
    
    Class Source
    Code:
    // Invoice Class File
    
    #include "Invoice.h" //Class definition file
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    Invoice::Invoice()
    {
    	price = 0;
    	amount = 0;
    	partNumber = "";
    	description = "";
    }
    
    void Invoice::setPartNum(string s)
    {
    	partNumber = s;
    }
    
    string Invoice::getPartNum()
    {
    	return partNumber;
    }
    
    void Invoice::setPartDesc(string d)
    {
    	description = d;
    }
    
    string Invoice::getPartDesc()
    {
    	return description;
    }
    
    void Invoice::setPartAmt(int a)
    {
    	amount = a;
    }
    
    int Invoice::getPartAmt()
    {
    	return amount;
    }
    void Invoice::setPartPrice(int p)
    {
    	price = p;
    }
    
    int Invoice::getPartPrice()
    {
    	return price;
    }
    
    Test
    Code:
    //Driver Test File for Invoice Class
    //This driver tests the invoice class with input from data.dat in the format specified
    
    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <sstream>
    #include <string>
    
    #include "Invoice.h"
    
    using namespace std;
    
    
    int main()
    {
    
    	Invoice i;
    	i.setPartNum("123");
    	i.setPartDesc("Red");
    	i.setPartAmt(1);
    	i.setPartPrice(20);
    
    	cout << i.getPartNum() << " " << i.getPartDesc() << " " << i.getPartAmt() << " " << i.getPartPrice() << " "; 
    
    	return 0;
    }
    
    
    Any help would be appreciated
    ------------------double post merged------------------
    NEVERMIND!

    dam compiler.

Share This Page