Explain syntax rules for writing constructor functions, C/C++ Programming

Assignment Help:

Syntax rules for writing constructor functions

  • Its name must be similar as that of the class to which it belongs.
  • It is declared with no return type (not even void). However, it will implicitly return a temporary copy of the instance itself that is being formed.
  • It cannot be declared static (a function which does not belong to a particular example), cost( in which you cannot make changes).
  • It should have public or protected access within the class. Only in very rare circumstances the programmers declare it in private section.

e.g.

class  boxclass

                 {

                  public :

                boxclass ( int x1, int y1, int x2, int y2);

                void disp(void);

                  private :

                                                int x1, y1;

int x2, y2 ;

 

                 };

 

boxclass::boxclass(int ax1,int ay1, int ax2, int ay2)

                 {

                                x1 = ax1 ;

                                y1 = ay1 ;

                                x2 = ax2 ;

                                y2 = ay2 ;

       }

 


Related Discussions:- Explain syntax rules for writing constructor functions

Write down the class listnode, Question: (a) Write down the class 'Li...

Question: (a) Write down the class 'ListNode' to contain the following:- (i) variable data of type Object (ii) variable next of type ListNode (iii)

Optimized nic driver for windows compact 7, Optimized NIC Driver for Window...

Optimized NIC Driver for Windows Compact 7 for Hard Real Time Communication Project Description: I am seeking an optimized driver (miniport driver) that will be used for sele

Quick sort , Hi, I need quick sort program without using recursion

Hi, I need quick sort program without using recursion

Define a class?, Define a class? A: It is an expanded concept of a data ...

Define a class? A: It is an expanded concept of a data structure: rather than holding only data, it can hold data and functions both.

Vectors, A body which has three forces acting on it is in equilibrium. One ...

A body which has three forces acting on it is in equilibrium. One force is 3N to the North and the other is 4N to the west. What us the magnitude and direction of the third force?

Area under curve, progarm in c for area under curve   #include ...

progarm in c for area under curve   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; int numtraps;

Define name mangling in c++??, A: The procedure of encoding the parameter t...

A: The procedure of encoding the parameter types along with the function/method name into a unique name is called as name mangling. The inverse procedure is called demangling. F

Chapter 21, Test scores solution help. Three member variables

Test scores solution help. Three member variables

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd