I have created a class Book that store 3 variables(string title, int pages, float price). I also have created 3 constructor but the null constructor keeps giving me errors. (58: error: request for member 'pages' in 'b1', which is of non-class type 'Book()') (61: error: request for member 'Info' in 'b1', which is of non-class type 'Book()')
#include <iostream>
#include <string>
class Book{
public:
std::string title;
int pages;
private:
float price;
public:
Book(){
title = "";
pages = 0;
price = 0;
}
Book(std::string bookTitle){
title = bookTitle;
pages = 0;
price = 0;
}
Book(std::string bookTitle, float bookPrice){
title = bookTitle;
pages = 0;
price = bookPrice;
}
void Info()
{
std::cout << "Title: " << title << std::endl;
std::cout << "Pages: " << pages << std::endl;
std::cout << "Price: " << price << std::endl;
}
void Pricing(float bookPrice)
{
price = bookPrice;
}
};
int main()
{
Book b1();
b1.pages = 100; //first error
Book b2("Mathimatics");
b2.pages = 200;
Book b3("Algebra", 50);
b3.pages = 300;
b1.Info(); //second error
b2.Info();
b3.Info();
}