Invoice Record Class

This is a discussion on Invoice Record Class within the C++ Programming forums, part of the General Programming Boards category; I am trying to create a class called record... every thing seems to be ok but it wont let me ...

  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
    21,936
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,936
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 04: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, 06:18 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21