Jump to content

A problem about constructor of a class (beginner's question)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
cytsunny

cytsunny

    Newbie

  • Members
  • Pip
  • 2 posts
I've been writing a library for my program. However, when I tried compiled the program, the debugger told me that I've return a value for the constructor. (Bold part in main code) However, the member function I've included in the constructor should be a void function and it doesn't returned any value at all. Do anybody know what's wrong?

header file:
#include <string>

using std::string;


class Invoice

{

private:

    string PartNumber;

    string PartDescription;

    int Quantity;

    int PricePerItem;

    int InvoiceAmount;

public:

    Invoice(string, string, int, int);

    void setInitial(string, string, int, int);

    void setPartNum(string);

    void setPartDescription (string);

    void setQuantity(int);

    void setPricePerItem(int);

    string getPartNumber();

    string getPartDescription();

    int getQuantity();

    int getPricePerItem();

    int getInvoiceAmount();

}
Main code for the library
#include <iostream>    

using std::cout;

using std::endl;


#include <string>

using std::string;


#include "Invoice.h"


[B]Invoice::Invoice(string part, string description, int number, int money)

{

    setInitial(part, description, number, money);

}[/B]

void Invoice::setInitial(string part, string description, int number, int money)

{

    PartNumber = part;

    PartDescription = description;

    Quantity = number;

    PricePerItem = money;

}

void Invoice::setPartNum(string part)

{

    PartNumber = part;

}

void Invoice::setPartDescription(string description)

{

    PartDescription = description;

}

void Invoice::setQuantity(int number)

{

    if (number >= 0)

        Quantity = number;

    if (number < 0)

    {

        cout << "quanity cannot be negative.\n";

        cout << "quanity set to 0\n";

        Quantity = 0;

    }

}

void Invoice::setPricePerItem(int money)

{

    if (money >= 0)

        PricePerItem = money;

    if (money < 0)

    {

        cout << "pricePerItem cannot be negative.\n";

        cout << "pricePerItem set to 0\n";

        PricePerItem =0;

    }

}

string Invoice::getPartNumber()

{

    return PartNumber;

}

string Invoice::getPartDescription()

{

    return PartDescription;

}

int Invoice::getQuantity()

{

    return Quantity;

}

int Invoice::getPricePerItem()

{

    return PricePerItem;

}

int Invoice::getInvoiceAmount()

{

    if ((Quantity * PricePerItem) >= 0 )

    {

        InvoiceAmount = Quantity * PricePerItem;

        return InvoiceAmount;

    }

    if (Quantity < 0 )

    {

        return 0;

    }

    if (PricePerItem < 0)

    {

        return 0;

    }

}


#2
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
The class declaration should end in a semicolon.

#3
cytsunny

cytsunny

    Newbie

  • Members
  • Pip
  • 2 posts
Hard to believe.......... but that's exactly the problem.......
It seems that the statement given by the debugger is just too far away from the real problem.

Thank you very much.