Hi.
I have a class named Product, each object of this class holds one product in a "store". The class also has a static int member to keep track of how many products there are.
iProducts is static member.
Constructor:
Product::Product(std::string name, int price, std::string description)
{
sName = name;
iPrice = price;
sDescription = description;
iProducts++;
}
Destructor:
~Product() {iProducts--;};
Is this a correct way of doing this?
Because the destructor gives -- right away when I define a new object of the class. The destructor should only run when object is deleted right?
Example:
Product milk = Product( "Milk", 7 , "Lot's of calcium");
Product mustard = Product( "Mustard", 35, "Very exclusive and good" );
cout << Product::iProducts;
Shows 0, if I don't use -- in constructor it gives me the correct 2.