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

What is namespace and explicit container, What is Namespace and Explicit ...

What is Namespace and Explicit container Namespace - Namespaces are used to group entities such as objects, classes and functions under a name. Explicit container.

Decoding, how to decode a number from mobile keypad

how to decode a number from mobile keypad

Static data members and static member function, Static Data Members: A ...

Static Data Members: A data member inside the class can construct as static data member.   There are few guidelines to be followed when declaring static data member.

Need to fix a code written in c++, Need to Fix a code written in c++,SDL2.0...

Need to Fix a code written in c++,SDL2.00 for high CPU and memory leak There is a 2D simple game written with SDL2.00 using c++. The game isn't complete and the code is a little

Simple object-oriented program, This assignment is to be undertaken individ...

This assignment is to be undertaken individually - no group work is permitted. Background information This assignment is an exercise in simple object-oriented programming and, acco

Coding, dispaly the last ant on rod

dispaly the last ant on rod

Oop, what is oop?

what is oop?

Data structure, Project Description: Project is related indexing data re...

Project Description: Project is related indexing data related some data structure. I need to share all information related project later if i contact any body Skills required

#podavan string, ##question.A Padovan string P(n) for a natural number n is...

##question.A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string co   program in jav

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