473,796 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why class keyword in C++



If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance.

Feb 17 '06 #1
12 1988
Viru Rathore wrote:
If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different
in struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.


Because it's cooler that way.

V
--
Please remove capital As from my address when replying by mail
Feb 17 '06 #2
Viru Rathore wrote:

If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance.

The point of OOD/OOP is information and process hiding by creating black
boxes with only the interfaces publicly available, (the need to know
basis for what is available). Hence for OOD/OOP development of an object
most of the data and methods would normally be private. But for backward
compatibility with old C code struct had to be supported with data and
methods defaulting to being public. Personally I always include explicit
declaration of scope, (private,protec ted or public), within an object.

JB
Feb 17 '06 #3
n2xssvv g02gfr12930 wrote:
Viru Rathore wrote:

If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance.

The point of OOD/OOP is information and process hiding by creating black
boxes with only the interfaces publicly available, (the need to know
basis for what is available). Hence for OOD/OOP development of an object
most of the data and methods would normally be private.


However, I find it much more logical to put the public members first, since
they are the part that is interesting for the largest group of people. So
my classes always start like:

class Foo
{
public:

It's similar with inheritance. The default is private, even though one
usually inherits publically way more often.

Feb 17 '06 #4
> However, I find it much more logical to put the public members first, since
they are the part that is interesting for the largest group of people. So
my classes always start like:

class Foo
{
public:

It's similar with inheritance. The default is private, even though one
usually inherits publically way more often.

This is right but i want to know that we can do the same thing in
struct.
If we want private then we can define as private or required public we
define as public.

So why make a keyword different from struct to class.

OOD/OOP requird class keyword so make compitible to that OOAD grammer
to make this keyword.

Feb 17 '06 #5
Viru Rathore wrote:
However, I find it much more logical to put the public members first,
since they are the part that is interesting for the largest group of
people. So my classes always start like:

class Foo
{
public:

It's similar with inheritance. The default is private, even though one
usually inherits publically way more often.

This is right but i want to know that we can do the same thing in
struct.
If we want private then we can define as private or required public we
define as public.


Yes. The two differences between the keywords struct and class are:

1. The default access / default inheritance
2. "class" can be used for a template parameter, "struct" can't.
So why make a keyword different from struct to class.
I guess it's just because the name "class" is so widespread for .... well, a
class.
OOD/OOP requird class keyword so make compitible to that OOAD grammer
to make this keyword.


Something like that, yes.

Feb 17 '06 #6
"Rolf Magnus" writes:
I guess it's just because the name "class" is so widespread for .... well,
a
class.


"class" was the word used in Simula 67, and perhaps before that. I checked
to see if Smalltalk preceded Simula 67 and chanced upon an interesting
article by Allan Kay. Which I will have to read some day when I have the
time. It's some of the early history of OOP.

http://gagne.homedns.org/~tgagne/con...storyST.html#4
Feb 17 '06 #7
Viru Rathore ha scritto:

If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance. I am not sure, but from what I understood (from strousdrup book) the
need of another keyword is
to avoid to modify C struct keyword and to mantain complete
consistence/compatibility with C.
ye
Pier Paolo

Feb 17 '06 #8

"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:67******** ************@co mcast.com...
Viru Rathore wrote:
If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different
in struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.


Because it's cooler that way.


Classier, anyway.

-Howard

Feb 17 '06 #9

"Viru Rathore" <ra************ **@gmail.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...


If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.


Backwards compatibility, both with C and with older C++ code, I assume.

In my first C++ compiler (Turbo C++ 2, I think), the keyword struct meant a
purely C-style struct, what we call a POD ("plain old data") structure
today. No member functions, no inheritance, simply public data. The class
keyword in that software indicated the new C++-style definition, with member
functions and inheritance allowed.

I (and many other programmers, I'm sure) still tend to program in that
fashion, using struct only for pure POD data holders, and class for
everything else.

-Howard
Feb 17 '06 #10

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

Similar topics

24
3307
by: Shao Zhang | last post by:
Hi, I am not sure if the virtual keyword for the derived classes are required given that the base class already declares it virtual. class A { public: virtual ~A();
14
2363
by: Jason Heyes | last post by:
I want to write a class that supports operations on keywords belonging to the C++ programming language. The following program repeatedly prompts the user for a keyword until 'explicit' is finally entered: #include <iostream> #include "KeyWord.h" int main() { KeyWord word;
20
2892
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
5
14439
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with the class and this works but I would also like to know of other ways to do this. Also are there any performance implacations of using sealed?
9
2501
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over ride just add aditional code ontop of the current class or completely over ride it in vb? I am use to C++ this is the first inherited thing I've done in VB.NET... I'm a little unsure of diffrences, could someone explain this to me some? thanks!
5
6867
by: Dylan Moreland | last post by:
I'm trying to implement a bunch of class methods in an ORM object in order to provide functionality similar to Rails' ActiveRecord. This means that if I have an SQL table mapped to the class "Person" with columns name, city, and email, I can have class methods such as: Person.find_by_name Person.find_by_city_and_name Person.find_by_name_and_city_and_email I have a metaclass generating basic properties such as .name and .city,
4
1664
by: key9 | last post by:
Hi All I 've got no idea how to describe it on subject. See code: //ABC class Keyword{}; // user's command class Handler{}; // command's action // A Command contain A Keyword* + A Handler*
4
1327
by: Miro | last post by:
Vb2003, im still learning vb.net but I do not understand my output from this logic. If someone can help me out here. Cor Ligthert, you I believe were on the right track of what Im trying to create. -Thank you very much for leading me on to Classes. Ok here is my code. ( see below )
3
2006
by: Hongyu | last post by:
Hi, I am a newbie in C++. I saw a code like the below and don't understand it. class A { public: A();
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.