Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ base constructor

class Derived: public Base
{
public:
    double m_cost;
 
    Derived(double cost=0.0, int id=0)
        : Base{ id }, // Call Base(int) constructor with value id!
            m_cost{ cost }
    {
    }
 
    double getCost() const { return m_cost; }
};
Source by www.learncpp.com #
 
PREVIOUS NEXT
Tagged: #base #constructor
ADD COMMENT
Topic
Name
5+6 =