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

DECODE, Smugglers are becoming very smart day by day. Now they have develop...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Program, Data array A has data series from 1,000,000 to 1 with step size 1,...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Ice_Cream Game, Do you have any solution on this activity?

Do you have any solution on this activity?

Super ASCII string cost, string will contain only lower case alphabet& the ...

string will contain only lower case alphabet& the ascii value starts from 1-26,(ie,a=1&z=26).it perform the operation like the following costs:add=2units,replace=1unit,delete=3unit

[email protected], Write a program to find the area under the curve y =...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Program to calls to echo the typed characters, Write a main program that us...

Write a main program that uses these system calls to echo the typed characters. The pseudo code will look something like: void traphandler ()  {    if (R0 == 0) { // read sys

Why should i employ new instead of truthful old malloc()?, Why should I emp...

Why should I employ new instead of truthful old malloc()? A: Constructors/destructors, type safety, overridability. Constructors/destructors: unlike malloc(sizeof(Fred)), new

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