friend - describe the 8th line of this c++ code? -


i learning c++, presently learned java(there no friend function concept on there). here on friends function section. btw know friend function allow access private , protected data of class..

i know "::" scope qualifier.
know ":?" conditional operator
box(): length(0) { } // code line confused me.
same blocks used in java or else.

#include <iostream>   using namespace std;   class box   {       private:           int length;       public:           box(): length(0) { }  // ****what ?? ******         friend int printlength(box); //friend function   };   int printlength(box b)   {       b.length += 10;       return b.length;   }   int main()   {       box b;       cout<<"length of box: "<< printlength(b)<<endl;       return 0;   }   

that default constructor box, initializing length member variable 0 when run. if tried change 0 in there example 12, boxes default length of 12. c++ constructor initialization list more information.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -