|
|
tech_list
. It's perfectly legal to call constructors, but you should not call them.tech_list
is a pointer, so anything in your for loops are working with an an initialized pointer.stealthy12341 wrote: |
---|
tech_list(int howmany) { num_items = 0; tech = new tech_list[howmany + 1]; } to tech_list(int howmany) { num_items = 0; tech_list *tech = new Tech[howmany + 1]; } initialize it? or would it be tech_list(int howmany) { num_items = 0; Tech *tech = new Tech[howmany + 1]; } |
|
|
|
|
tech_list
in main, but dynamically allocate the pointer within the class of tech_list
.
|
|
tech_list
before working on other parts of the code.
|
|
|
|
void tech_list::input()
|
|
++num_items
. You called this function after you instantiated the object inside main, so I assume that this function is called right after any object of the class is instantiated. I think you are meaning to use a loop here instead.
|
|
|
|
tech_list tech
in main is not suppose to be an array. Or at least I don't think it is. It just doesn't make sense to me to have a list of lists. Shouldn't one list be enough?Tech::~Tech
isn't deleting arrays correctly. If you dynamically allocate an array, you must deallocate them properly as well. Only two of the pointers are deallocated properly (the non char arrays).tech_list::tech_list(int howmany)
should look like (or similar):
|
|
cin.ignore()
after you use getline()
. It just makes the program pause such that you'll have press the enter key again, which can be annoying.$ g++ main.cpp class.cpp -Wall -Wextra -o "program.out" $ ./program.out How many items would you like to input? 3 Please enter the items. We are working with item #: 1 Please enter the items name: Pencil Please enter the item description: It's a bright yellow no. 2 pencil. Please enter the cost of the item: 0.99 Please enter the item's best advantage: Can write things. Please enter the item's worst disadvantage: Has to sharpen every once a while. Please rate the item from 1 to 5 stars: 3 We are working with item #: 2 Please enter the items name: Danish Pastry Please enter the item description: Sweet, savory snacks Please enter the cost of the item: 3.99 Please enter the item's best advantage: It's good Please enter the item's worst disadvantage: None Please rate the item from 1 to 5 stars: 5 We are working with item #: 3 Please enter the items name: Multivitamin pill Please enter the item description: For those who skip lunch Please enter the cost of the item: 1.99 Please enter the item's best advantage: Keeps you somewhat healthy? Please enter the item's worst disadvantage: It's a pill Please rate the item from 1 to 5 stars: 3 Name: Pencil Description: It's a bright yellow no. 2 pencil. Cost: 0.99 Pros: Can write things. Cons: Has to sharpen every once a while. Rated: 3 Name: Danish Pastry Description: Sweet, savory snacks Cost: 3.99 Pros: It's good Cons: None Rated: 5 Name: Multivitamin pill Description: For those who skip lunch Cost: 1.99 Pros: Keeps you somewhat healthy? Cons: It's a pill Rated: 3 $ |
tech
. You should not and cannot. Use the members of tech_list
to access the private member instead, which is shown above. It's done via the function tech_list::input()
.