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

Explain conversion functions, Conversion Functions Conversion functions...

Conversion Functions Conversion functions are member functions used for the following purposes: 1. Conversion of object to basic data type. 2. Conversion of basic data ty

Define the return statement in computer programming, Define The Return Stat...

Define The Return Statement in Computer Programming? The return statement is used for two purposes once the return statement is executed the program control will be immediately

Need cron job parsing json from api, Need Cron Job Parsing JSON from API, I...

Need Cron Job Parsing JSON from API, Inserting in to DB Project Description: The Project is to prepare a Cron Job with an adjustable interval in seconds and milli seconds. Cr

Implement the c++ code in assembly language, Selecting Array Elements Imple...

Selecting Array Elements Implement the following C++ code in assembly language, using the block-structured .IF and .WHILE directives. Assume that all variables are 32-bit signed in

Recursion, #questiowrite a program to calculate e^x

#questiowrite a program to calculate e^x

Algorithms, algorithm to find out all the factors of given positive integer...

algorithm to find out all the factors of given positive integers

Prime no., program to find if a no . is prime or not

program to find if a no . is prime or not

Star, Write a program that finds the minimum total number of shelves, inclu...

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

Programs that perform the identical recursive algorithm, Goals For this ass...

Goals For this assignment you will write programs in C and LC-3 assembly code. Both programs will perform the identical recursive algorithm. The goals of this programming assignmen

Explain relational operators, Relational Operators A relational operato...

Relational Operators A relational operator is used to make comparison among two values. All these operators are binary and needs two operands. There are the following relationa

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