Thursday, July 30, 2009

Can u say briefly about friend function,constructor and destructor in c++?

Friend Function:


When it is required that a function from class A should be able to access the members of Class B then you make this function from Class A as friend of Class B.





Constructors:


Constructors are used to initialize the member variables. If it is required that some memory allocation or initilization is to be done you can do this in constructor. Constructors should of the same name as that of the class.





Destructors:


As you have constructors you also have destructors. Destructors are used to free any resources your class has explicitly used. For instance, you have allocated memory to member variable "b" then the best place to free this memory would be the destructor of the class.


Destructors are also of the same name as that of the class and always start with "~" character.

Can u say briefly about friend function,constructor and destructor in c++?
not a c++ guru, but friend is a accessibility keyword indicates that the function, destructor, or constructor can only be used by classes in the same library that access the class containing the friend function.





External libraries or applications that reference the library containing this class will be unable to access any functions protected by the friend keyword.
Reply:plz read the book balaguruswami.

radiata

No comments:

Post a Comment