473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the Purpose of Constructor in a class?

Hi,

Constructor of a class is only used to Intialize the Instance
variable of class or it will allocate the member and then Intialize
the variable?........

If constructor is used only to Intialize the Instance variable of
the class, What is the need of Constructor in Abstract
class?.............

Mar 12 '06 #1
6 7588
rv*******@gmail.com wrote:
Hi,

Constructor of a class is only used to Intialize the Instance
variable of class or it will allocate the member and then Intialize
the variable?........
Initialize members.

If constructor is used only to Intialize the Instance variable of
the class, What is the need of Constructor in Abstract
class?.............


No need. You generally don't write one for abstract class.

Regards,
Ben
Mar 12 '06 #2
* rv*******@gmail.com:
Hi,

Constructor of a class is only used to Intialize the Instance
variable of class or it will allocate the member and then Intialize
the variable?........
The question is very unclear, seemingly self-contradictory.

There is no conflict between "initialize the instance" and "allocate the
member" (using a liberal interpretation so as to make the latter
meaningful); the latter is generally a part of the former.

Anyway what initialization a constructor needs to do depends solely on
the class' invariant, which is the set of assumptions that you guarantee
will hold for every instance.

If constructor is used only to Intialize the Instance variable of
the class, What is the need of Constructor in Abstract
class?.............


An abstract class is not different from other classes in this respect.

What difference did you think there would be?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 12 '06 #3
* benben:
rv*******@gmail.com wrote:
Hi,

Constructor of a class is only used to Intialize the Instance
variable of class or it will allocate the member and then Intialize
the variable?........


Initialize members.


A constructor can and usually will do some allocation.

If constructor is used only to Intialize the Instance variable of
the class, What is the need of Constructor in Abstract
class?.............


No need. You generally don't write one for abstract class.


I certainly write constructors for abstract classes.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 12 '06 #4
GB
benben wrote:
rv*******@gmail.com wrote:
Hi,

Constructor of a class is only used to Intialize the Instance
variable of class or it will allocate the member and then Intialize
the variable?........


Initialize members.

If constructor is used only to Intialize the Instance variable of
the class, What is the need of Constructor in Abstract
class?.............


No need. You generally don't write one for abstract class.


That may be true for the special case of purely abstract base classes
that are not derived from anything, but otherwise it is not true. An
abstract class many have a base class that has a non-default constructor
that requires parameters that have to be passed up. The abstract class
may also have its own data members.

Gregg
Mar 12 '06 #5
> A constructor can and usually will do some allocation.

I didn't say it doesn't. I just said I doesn't allocate members.

Regards,
Ben
Mar 13 '06 #6
* benben:
A constructor can and usually will do some allocation.


I didn't say it doesn't. I just said I doesn't allocate members.


I think, with a question that's not framed in perfect English, but
rather imperfect English, one should try to interpret it in a way that's
meaningful, or else just answer that question seems to be meaningless,
or not answer it at all (of course that's just my opinion).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
1
by: gerg | last post by:
for a class such as: class A { public: A(); ///// leave everything missing for purpose of example public: /// member vars
17
by: baibaichen | last post by:
i have written some code to verify how to disable slicing copy according C++ Gotchas item 30 the follow is my class hierarchy, and note that B is abstract class!! class B { public: explicit...
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
25
by: raylopez99 | last post by:
First in an occasional series. I'm somewhat experienced in C++, and am using .NET Visual Studio 2005 as the IDE. I'm learning C#. What I don't like about C#, compared to C++ (all flavors): ...
28
by: gnuist006 | last post by:
I have some code like this: (if (test) (exit) (do something)) or (if (test)
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.