I saw the following code in a friend's program
He said it's declared that way, because the 'boo' value is being assigned to the PQ variable before the function body gets called.Code:class ABC { public: std::string PQ; public: testIt(); }; //the line below is where I have an issue ABC::ABC(std::string boo) : PQ(boo) { //some code }
My question is, why did C++ have a provision to assign a value in this way? Why not just assign it like
Why did C++ provide the ": PQ(boo)" type of functionality?Code:ABC::ABC(std::string boo) { PQ=boo; //some code }




Reply With Quote