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

Board coloring, n this problem u given a board in which some of the element...

n this problem u given a board in which some of the elements are placed as shown in diagram below .each element represent a color .fill the other elements in the board such that no

Decodethecode, 6999066263304447777077766622337778 -----> message sent by th...

6999066263304447777077766622337778 -----> message sent by the first smuggler. my name is robert---------> message decoded by the second smuggler. Where ‘0’ denotes the "space".

Create a stack using arrays, Problem : (a) Stacks can be implemented u...

Problem : (a) Stacks can be implemented using arrays. Write down the following C or C++ function to (i) create a stack (ii) add an element to a stack (push). (b) Expl

Write a program to illustrate array of structures, Write a program to illus...

Write a program to illustrate array of structures? struct customer { int id; char name[15]; }; struct customer c[100]; . In the above instance, the array of Structures is

Implement binary heap in c++?, A:BinaryHeap.h ------------ #ifndef BI...

A:BinaryHeap.h ------------ #ifndef BINARY_HEAP_H_ #define BINARY_HEAP_H_ #include "dsexceptions.h" #include "vector.h" // BinaryHeap class // CONSTRUCTION: wi

Explain high-order and low-order bytes., Explain high-order and low-order b...

Explain high-order and low-order bytes. - Numbers are written from left to right in decreasing order of significance. In the same way, bits in a byte of computer memory can be

Wap for basic salary of employees & calculate net salary, WAP TO ACCEPT THE...

WAP TO ACCEPT THE BASIC SALARY OF EMPLOYEES & CALCULATE NET SALARY   #include stdio.h> #include conio.h>   void main() {                    float Basi

Decode the code, c++ coding decode the letters from numbers

c++ coding decode the letters from numbers

Integration, w.a.p to find outWrite a program to find the area under the cu...

w.a.p to find outWrite 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.

Explain the pointer types, Pointer Types Pointer holds the address of a...

Pointer Types Pointer holds the address of an object, permitting for the indirect manipulation of that object. They are used in creating linked data structures like lists, tree

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