Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

constructor init 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;
};
 
PREVIOUS NEXT
Tagged: #constructor #init #list
ADD COMMENT
Topic
Name
2+3 =