Explain the process of using the constructor, C/C++ Programming

Assignment Help:

Using the Constructor

There are basically three ways of creating and initializing the object. The first way to call the constructor is explicitly as :

                                boxclass bigbox = boxclass ( 1,1,25,79);

This statement makes an object with the name bigbox and initializes the data members with the parameters passed to the constructor function. The above object can also be formed with an implicit call to the constructor :

                boxclass bigbox(1,1,25,79);

Both the statements given above are equivalent. Yet, another way of creating and initializing an object is by direct assignment of the data item to the object name. But, this approach works if there is only single data item in the class. This is obvious because we cannot allocate more than one value at a time to a variable.

e.g.

                class counter

                 {

                   public :

                                                counter ( int c)   // constructor.

                                                 {

                                                                count = c;

                                                 };

                   private :

                                                int  count;

 

 };

 

 


Related Discussions:- Explain the process of using the constructor

Car rental project, I need a project on car rental system using c programmi...

I need a project on car rental system using c programming only of college level

Write a program that finds the minimum total number of shelv, At a shop of ...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Explain concept of object initialization, Object Initialization An obje...

Object Initialization An object of a derived class can be initialized to an object of a base class. If both the classes have similar data members, then no specific constructor

Loop, Write a program that writes your name on the monitor ten times. Write...

Write a program that writes your name on the monitor ten times. Write this program three times, once with each looping method.

Define bitwise left shift and right shift operators, Define Bitwise Left Sh...

Define Bitwise Left Shift and Right Shift Operators: >? The bitwise shift operators shift their first operand right (>>) or left ( // Illustration of the bitwise right shi

Type compatibility, Define  T y pe c o m p a t i b i li t y? ...

Define  T y pe c o m p a t i b i li t y? T o a s s i g n i n t t o s m a l l i n t t h e v a r i a b l e should b e

What is an explicit constructor, A conversion constructor declared with the...

A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to execute an implied conversion of types. Its purpose is reserved ex

When does a name clash occur in c++, A name clash happens when a name is de...

A name clash happens when a name is described in more than one place. For example, two dissimilar class libraries could give two different classes the similar name. If you try to u

Give a formal expression of the specification, A function REPAT is specifie...

A function REPAT is specified below. Function REPAT(c in Char, i in Int, s in mString) return in mString pre 1 ≤ i ≤ the length of s. post The returned value is a string identic

Describe the theoretical concepts of binary files, Question 1 Explain the ...

Question 1 Explain the concept of constructors and destructors in C++ with programming examples Question 2 Explain the concepts and applications of multiple inheritance and v

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