I am a new one who have joined u plz try to help me bcoz i could not
find ny sutiable answer foer this Question
Qus>>why do we need classes when structures provide similar
functionality?? 14 3726
structures are public by default and classes are private by default.
Unless you use the keywords private, public or protected, any member
funtions or member data in a structure will be public. The idea behind
encapsulation is to hide the details, it is desireable to make private
data and provide public interface methods that the user of the class
can use.
On 27 Feb 2005 19:34:41 -0800, "Pratts" <it*********@rediffmail.com>
wrote in comp.lang.c++: I am a new one who have joined u plz try to help me bcoz i could not find ny sutiable answer foer this Question Qus>>why do we need classes when structures provide similar functionality??
A better way to ask this question would be:
"Why do we need structs in C++ when we have classes?"
There is a difference in default access, but this is really trivial.
Structs are needed for backwards compatibility with C code, of which
there were millions of lines in existence as C++ came into being.
Classes are little more than a documentation mechanism.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
"Pratts" writes: I am a new one who have joined u plz try to help me bcoz i could not find ny sutiable answer foer this Question Qus>>why do we need classes when structures provide similar functionality??
If you mean why do we need the keyword "class" in addition to stuct, the
answer is, we don't. It's just for convenience and, as typically used,
improves documentation.
"Pratts" <it*********@rediffmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... I am a new one who have joined u plz try to help me bcoz i could not find ny sutiable answer foer this Question Qus>>why do we need classes when structures provide similar functionality??
structures do not provide anywhere near the functionality you get from
classess.
Classess have constructors, that can be modified./overloaded.
Classes have destructors, that can be modified/ overloaded.
Classes allow for operator Overloads.
Classes have member functions, static functions.
Public, Private, and Protected Data and code.
Classes incapsulate. Structures Arrange.
The differences are vast. You will have to write some code to begin to
understand the impact.
I struggled with it for several months.
You gain Power, Robustness. A level of Protection, while increasing the
longevity of your code.
I can send you some examples done with both structures and class object, if
you'd like to see the difference.
dan DH*************@cox.net
> Classess have constructors, that can be modified./overloaded. Classes have destructors, that can be modified/ overloaded. Classes allow for operator Overloads. Classes have member functions, static functions. Public, Private, and Protected Data and code. Classes incapsulate. Structures Arrange.
struct was upgraded in C++ and can do all of that too. Try it.
I personally stopped using the class keyword and went back to struct.
The reason is I can eliminate that silly "public:" statement at the
beginning needed to expose the constructor. In the end, "class" proved
to be just an unnecessary annoyance with no value add for me. I do use
public, protected, and private extensively to define structs.
>> Classess have constructors, that can be modified./overloaded. Classes have destructors, that can be modified/ overloaded. Classes allow for operator Overloads. Classes have member functions, static functions. Public, Private, and Protected Data and code. Classes incapsulate. Structures Arrange.
struct was upgraded in C++ and can do all of that too. Try it.
I personally stopped using the class keyword and went back to struct. The reason is I can eliminate that silly "public:" statement at the beginning needed to expose the constructor. In the end, "class" proved to be just an unnecessary annoyance with no value add for me. I do use public, protected, and private extensively to define structs.
Indeed. I think that 'class' and 'struct' where meant to be equivalent. I never
touched another class after reading what Bjarne Stroustrup wrote about it in the
Annotated C++ Reference Manual, Addison-Wesly Publishing Company, 1995,
Paragraph 11.2:
<quote>
(...) For example, novices often don't know about access specifiers and get
confused by this:
class X { public: f(); };
class Y : X { }; // no access specifier
// private by default
void g(Y* p)
{
p->f(); // error
}
Even experts can get caught. A compiler can be most helpful by issuing a warning
for the missing access specifier.
Having private as the default was chosen to reflect the general view that
things that are not explicitly declared public are private. Defining a default
access specifier was probably a mistake.
</quote>
He says that the default access specifier 'private' for classes was a mistake.
There should have been _no_ default access specifier, ie class should be
'public' by default, just like struct is. The difference between class and
struct is based on a mistake. A class was meant to act just like a struct does.
"Pratts" <it*********@rediffmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... I am a new one who have joined u plz try to help me bcoz i could not find ny sutiable answer foer this Question Qus>>why do we need classes when structures provide similar functionality??
we r n nglsh lang nwsgrp her, not IM
try complt wrds nxt tm
buddy very sorry to say that
u must go through the things again bcoz structures can do all that
constructor
destructors
operator Overloads and every thing that class can do
plz try this out
byEEEEEEEEEEE
"Pratts" <it*********@rediffmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com... buddy very sorry to say that u must go through the things again bcoz structures can do all that constructor destructors operator Overloads and every thing that class can do plz try this out byEEEEEEEEEEE
Can structures have pure virtual Functions?
Can a structure prevent a programmer from erroneously ovewriting data
elements?
Can a structure have Private data?
Can a structure have Protected data?
The truth is I'm not sure, I use structs to set up Common data that the
Class objects will be using, and sharing with the outside world.
DHOLLINGSWORTH2 wrote:
[ ... ] structures do not provide anywhere near the functionality you get from classess.
Not true.
Classess have constructors, that can be modified./overloaded. Classes have destructors, that can be modified/ overloaded. Classes allow for operator Overloads. Classes have member functions, static functions. Public, Private, and Protected Data and code. Classes incapsulate. Structures Arrange.
In C++, all of the above statements apply equally to structs as
classes. The ONLY difference between a struct and a class in C++ is the
default visibility (private for class, public for struct). C++ allows
structs to have ctors, dtors, operator overloads, member functions and
public, private and protected members. You can derive one struct from
another struct, or even derive a struct from a class or a class from a
struct.
As an aside: destructors are only _rarely_ overloaded, and there are
only two overloads: one that is used when exiting a placement new via
an exception, and the usual one (no parameters, no cv-qualifiers)
that's used all the rest of the time.
--
Later,
Jerry.
The universe is a figment of its own imagination.
"Jerry Coffin" <jc*****@taeus.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
.... As an aside: destructors are only _rarely_ overloaded, and there are only two overloads: one that is used when exiting a placement new via an exception, and the usual one (no parameters, no cv-qualifiers) that's used all the rest of the time.
In fact, '_rarely_' is never. You are thinking of
the operator delete overload that will (or should)
match an operator new used in a placement new.
The only time destructors are run automatically
by a correct C++ compiler is after construction
of the object has successfully completed.
There is no such thing as an overloaded destructor.
--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
"Larry Brasfield" <do***********************@hotmail.com> wrote in message
news:%N**************@news.uswest.net... "Jerry Coffin" <jc*****@taeus.com> wrote in message news:11**********************@g14g2000cwa.googlegr oups.com... ... The only time destructors are run automatically by a correct C++ compiler is after construction of the object has successfully completed.
Hmmm, so when I successfully create an object, the destructor is called?
That kind of screws up my whole design... I was planning on using those
newly constructed objects! :-) Care to re-word that, or explain what you
mean a little better?
-Howard
"Howard" <al*****@hotmail.com> wrote in message
news:eV********************@bgtnsc04-news.ops.worldnet.att.net... "Larry Brasfield" <do***********************@hotmail.com> wrote in message news:%N**************@news.uswest.net... "Jerry Coffin" <jc*****@taeus.com> wrote in message news:11**********************@g14g2000cwa.googlegr oups.com... ... The only time destructors are run automatically by a correct C++ compiler is after construction of the object has successfully completed.
Hmmm, so when I successfully create an object, the destructor is called? That kind of screws up my whole design... I was planning on using those newly constructed objects! :-) Care to re-word that, or explain what you mean a little better?
(I might suggest you read more carefully. ;-)
Q. When are destructors ever run automatically?
A. Sometime after successfull construction of
temporary objects and auto storage class objects.
I did not say that destructors are run automatically
upon all successfully constructed objects, nor did I
suggest they are run immediately after construction.
So you can go ahead and keep using your objects!
My statement could have been more clearly written.
--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
> "Howard" <al*****@hotmail.com> wrote in message news:eV********************@bgtnsc04-news.ops.worldnet.att.net... Hmmm, so when I successfully create an object, the destructor is called? That kind of screws up my whole design... I was planning on using those newly constructed objects! :-) Care to re-word that, or explain what you mean a little better?
(I might suggest you read more carefully. ;-)
A good book to read at this time is a book about the logical thinking
machine, by lewis carrol.
I'm sorry I cant remember the Title, but logic was in the title, the cover
is pink and blue.
You'll communicate with your computer better when your done. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert |
last post by:
I have two tables (classes and students). Right now, I'm generating a
report in asp that shows a list of classes, the enrollment for each
class, and how many seats are available (see query below)....
|
by: cm500 |
last post by:
I'm very new to databases so bear with me. What I need is a way to
track the training for the employees at my firm. I have 40 classes
that I will be teaching on various subjects and various...
|
by: Benne Smith |
last post by:
Hi,
I have three enviroments; a development, a testing and a production
enviroment. I'm making a big application (.exe), which uses alot of
different webservices.
I don't use the webservices...
|
by: Andrew S. Giles |
last post by:
OK, Ive run my head into this wall for too long. I need help.
I am developing an applicaiton in C# to present a user with a GUI to specify
a configurable list of machines that he wants to listen...
|
by: Tim Geiges |
last post by:
Since I am being challenged with learning c# I figured I could pass
some of the pain on to you guys :-)
I have another question(this one is important for me to fix before I
can get my app to Beta)...
|
by: bonk |
last post by:
I have a set of unmanaged c++ classes that internally need to use
managed classes (WPF formerly know as "Avalon") but I do not want to
compile the whole MFC project with the /clr switch. What...
|
by: Luke Meyers |
last post by:
So, just a little while ago I had this flash of insight. It occurred
to me that, while of course in general there are very good reasons for
the conventional two-file header/implementation...
|
by: bsruth |
last post by:
I tried for an hour to find some reference to concrete information on
why this particular inheritance implementation is a bad idea, but
couldn't. So I'm sorry if this has been answered before....
|
by: Tyno Gendo |
last post by:
Hi everyone
I need to move on a step in my PHP...
I know what classes are, both in PHP4 and 5 and I'm aware of "patterns"
existing, but what I'm looking for are some real world projects eg....
|
by: =?Utf-8?B?SmF5IFZpbnRvbg==?= |
last post by:
I see general messages about how to learn .NET but I have an immediate
requirement to ramp up my old skills very quickly.
Can anyone recommend the FASTEST way for me to get almost-competent in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |