Not sure how to alleviate this issue (see title). I went ahead and was in the process (not finished I assume due to the error) of revamping a program that used struct: https://pastebin.com/FDBjNeUn --(original code before revamping to class)
Currently I have these for my main.cpp, Product.h, and Product.cpp:
If the 0-arg Product constructor must be private, then don't call it.
Call new Product(code, string, price);.
If you're getting some infinite loop, my first guess would be you entered invalid data and your input stream is now in a bad state.
In the loop that is infinite, add:
1 2 3 4
if (!cin)
{
cout << "Error: Bad input state\n";
}
This will at least confirm that (but won't stop the loop).
To clear the state of cin, you can do:
1 2 3 4 5 6 7 8 9 10 11
#include <limits>
// ...
if (!cin)
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
// attempt to get user input again