Professional Documents
Culture Documents
● If you don’t define any constructor, compiler will declare one for you. This
is compiler-generated default constructor.
● If you declare a constructor which takes no argument then it is explicitly
defaulted constructor.
● With compiler-generated default constructor, you can’t declare array of
objects.
Explicitly Deleted Constructor
Constructor Initializer
Copy Constructor
When called?
private:
double r;
double i;
};
class Sample {
Private:
private:
double r;
double i;
};
Destructor
Data Member: Static Types
const Data Members
Static Methods
const Methods
Mutable Data Members
Sometimes you write a method that is “logically” const but happens to change a
data member of the object. This modi cation has no effect on any user-visible
data, but is technically a change, so the compiler won’t let you declare the
method const. For example, suppose that you want to pro le your spreadsheet
application to obtain info about how often data is being read. A crude way to do
this would be to add a counter to the SpreadsheetCell class that counts each
call to getValue() or getString(). Unfortunately, that makes those methods
non-const in the compiler’s eyes, which is not what you intended. The solution
is to make your new counter variable mutable, which tells the compiler that it’s
okay to change it in a const method.
Inline Methods
➢ How to?
➢ Advantages.
Reference
➔ Marc Gregoire
(Chapter- 7, 8)