Thread: Invoice Record Class

  1. #1
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115

    Invoice Record Class

    I am trying to create a class called record... every thing seems to be ok but it wont let me compile it... i keep getting this error
    Code:
    error C3867: 'Record::printRecord': function call missing argument list; use '&Record::printRecord' to create a pointer to member
    reffering to "a.printRecord;"

    what am i doing worng :S

    Code:
    class Record {
    private: 
    	std::string item;
    	int invoiceNum; 
    	double cost;
    	int date;
    public:
    	Record(std::string item, int invoiceNum, double cost, int date);
    	void inputRecord(std::string, int, double, int);
    	void printRecord();
    };
    Record::Record(std::string = "item", int = 0000000, double = 00.00, int =  32) {
    	item = item;
    	invoiceNum = invoiceNum;
    	cost = cost;
    	date = date;
    }
    void Record::inputRecord(std::string item, int invoiceNum, double cost, int date) {
    	item = item;
    	invoiceNum = invoiceNum;
    	cost = cost;
    	date = date;
    }
    void Record::printRecord() {
    	printf("%s\t\t%i\t$ %f\t%i/08/06\n", item, invoiceNum, cost, date);
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    	Record a,b("Item", 1234567, 00.00, 12);
    
    	a.inputRecord("sdersdfg sdf fff", 7654321, 99.99, 20);
    
    	a.printRecord;
    	b.printRecord;
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
        a.printRecord();
        b.printRecord();

  3. #3
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Quote Originally Posted by robwhit View Post
    Code:
        a.printRecord();
        b.printRecord();
    Thats, that was a stupid mistake... lol.. should of picked that up myself..

    it all works now, but the data i am getting back is all over the shop :S

    Code:
    (null)          -858993460      $ -925596313493155010000000000000000000000000000
    00000000000000000.000000        -858993460/08/06
    (null)          -858993460      $ -925596313493155010000000000000000000000000000
    00000000000000000.000000        -858993460/08/06
    Press any key to continue . . .

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Looks like there are other problems:
    1. Your constructor definition has illegal syntax. For example, the first parameter does not have a name.

    2. In both your constructor and inputRecord() member function, you assign the arguments to themselves. You either have to use different names for the member variables or arguments, or prefix the member variables with this->.

    3. You attempt to use printf() with a %s format specifier on a std::string. I suggest either using an I/O stream, or using the c_str() member function of std::string.

    EDIT:
    Oh wait, looks like the constructor syntax is legal! Unfortunately, I cannot figure out what it means, and I am sure what it means is not what you want.
    Last edited by laserlight; 08-09-2007 at 11:57 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Quote Originally Posted by laserlight View Post
    Looks like there are other problems:
    1. Your constructor definition has illegal syntax. For example, the first parameter does not have a name.

    2. In both your constructor and inputRecord() member function, you assign the arguments to themselves. You either have to use different names for the member variables or arguments, or prefix the member variables with this->.

    3. You attempt to use printf() with a %s format specifier on a std::string. I suggest either using an I/O stream, or using the c_str() member function of std::string.

    EDIT:
    Oh wait, looks like the constructor syntax is legal! Unfortunately, I cannot figure out what it means, and I am sure what it means is not what you want.
    Thanks laserlight, It was my first attempt at a class... and it works now thanks

    Code:
    class Record {
    private: 
    	std::string item;
    	int invoiceNum; 
    	double cost;
    	int date;
    public:
    	Record(std::string = "item", int = 0000000, double = 00.00, int =  32);
    	void inputRecord(std::string, int, double, int);
    	void printRecord();
    };
    Record::Record(std::string _item, int _invoiceNum, double _cost, int _date) {
    	item = _item;
    	invoiceNum = _invoiceNum;
    	cost = _cost;
    	date = _date;
    }
    void Record::inputRecord(std::string _item, int _invoiceNum, double _cost, int _date) {
    	item = _item;
    	invoiceNum = _invoiceNum;
    	cost = _cost;
    	date = _date;
    }
    void Record::printRecord() {
    	std::cout << item << "\t\t"
    			<< invoiceNum << "\t\t$ "
    			<< cost << "\t"
    			<< date << "/08/06\n";
    }

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    include the header files string windows.h and cstdio, for std::string _TCHAR and printf. this does nothing:
    Code:
    	item = item;
    	invoiceNum = invoiceNum;
    	cost = cost;
    	date = date;
    haven't seen this notation before:
    Code:
    Record::Record(std::string = "item", int = 0000000, double = 00.00, int =  32)
    I would suggest writing in the parameter names.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah, I kind of figured out what that syntax means, and I guess you might have as well: it is just the "parameter names can be left out until the definition" with a default argument thing. It is rather strange that it came with the member function definition rather than in the class declaration, and that threw me off.

    In its current form, your code is fine, though I still suggest having the parameter names so as not to confuse others.

    Incidentally, you might want to use a constructor initialisation list instead of assigning in your constructor.

    I would also caution against using variable names with a leading underscore. If you happen to follow that with another underscore, or with an uppercase letter, or use the name for a global variable, then you would have used a name reserved to the implementation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Replies: 7
    Last Post: 05-26-2005, 10:48 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM