c++ - Why isn't my class constructor initializing its member variables? -


I'm sorry if there is a lack of information because I'm trying to follow "Asking Guidelines".

I have created a category called "item" to store the item information and defined my constructor as follows:

  item :: items (std :: String number, std :: string name, int volume, double price) {itemNumber = number; ItemName = Name; Quantity = quantity; UnitPrice = value; }   

and I like to start it in my main function:

  item temp ("string", "string", 0, 0) ;   

But when I printed the item's prices, only the item number and item name was printed properly. The random garbage that was printed then I realized that the issue is of the quantity and the value is not starting. Why is it like this?

Try

  this-> quantity = quantity;   

or (IMHO better):

  item :: items (const std :: string & number, const std :: string & name, int quantity_), double price) {// ^ // ... quantity = quantity_; // ...}   

or (Imho also better) use a constructor initiator list:

  items :: items (const std :: String & amp; item number (number), object name (name), quantity (quantity), unit value (value) {}   
P> "why so

The name of the parameter currently shines your member variable name in the constellation body of the constructor.


Personally But I have class announcements like

  square item {s} ItemNumer_ (number), ItemName (name), Quantity_ (volume), UnitPrice (value) {item} (Item code: Constrode :: String and number, Constrode :: string and name, int volume, double price) } Private: std :: string itemNumber_; Std :: string itemName_; int volume_; double unit process_};    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -