class Book {
private:
const std::string title;
const int pages;
public:
Book()
: title("Diary"), pages(100) {} // Member initializer list
};
class Parent
{
//public member or methods can be seen and accessed by any other object
public:
Parent(int publik, int protect, int privat)
: mPublik(publik), //with the colon starts the initializing list
mProtect(protect), //it sets the member of the object being created
mPrivat(privat) //used as if the member were 'methods'
//it has to be between a constructors head and body
{
//nothing to do here if you just want to set your members
}
int mPublik;
//protected member or methods of a class will be seen in child objects but
//not objects of other classes
//this is something in between private and public
protected:
int mProtect;
//private member or methods wont be seen by child members or objects of
//other classes
private:
int mPrivat;
};
class Book {
private:
const std::string title;
const int pages;
public:
Book() {
title = "Diary"; // Error: const variables can't be assigned to
pages = 100; // Error: const variables can't be assigned to
};