I ran the program, and it crashed. So I debugged it, and found that when reading the strings, I got an error of "error reading characters of string" and debugging some more got me some weird numbers like x00000 or something.
However, if in the main I do something like:
1 2 3 4 5 6 7 8 9 10 11 12
#include "Book.h"
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string a = "Reading";
int b = 56;
Book(a, b);
}
Then I don't get an error and it works fine. What can I do so that the first method works because that is the way I need to get it to work?
That's really strange. My code looks identical to that in relation to the constructor and data fields (although my data fields are private). And when I debug I get an error on reading the strings in, and int comes out to a gigantic negative number.
#include "Book.h"
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string a = "Reading";
int b = 56;
Book(a, b); /// wrong, create an object like Book obj1(a, b);
}
Int main(), rather than creating the book using Book(a, b); try using Book book1{a, b};, or skip the individual variables and use Book book1{ "Reading", 56 };