473,387 Members | 1,904 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,387 software developers and data experts.

Class vs struct

I have been searching for the differences between struct and class but at the end what i got is that they have just difference of only their default access. By default class has private access and struct has public. but we can make it it private by using keyword private: in it body. Both show similar kind of operations and similar kind of inheritance. Then what was the need of making class in OOP yep if we can deal with struct then why did "Bjarne stroustrup" made this syntax.??
Nov 10 '12 #1
1 1734
weaknessforcats
9,208 Expert Mod 8TB
You are corrrect. There is no difference between a class and a struct except for the default access. So if you declare the access of each of your members the class and struct are identical.

The reason for a class at all is to make C++ look like an object-oriented language when it really isn't one. In the object-oriented world (UML for example) an object is an instance of a class. Not an instance of a struct. However, by seeing "class" in C++ people can relate that to a UML class. The fact that "class" in C++ is just a fancy struct would be of interest only to C progrmmers learning C++.
Nov 10 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: matro | last post by:
hi there, I have the following struct in my class: class CTbStDialog : public CDialog { public: int fooVar, fooVar2; ... //other foo variables...
4
by: Erik H. | last post by:
I have an ASPX page in which I am trying to bind a datagrid to a dataset pulled from Microsoft Access DB using code inline method. For some reason, the compiler is having a problem with 'using'....
6
by: SB | last post by:
I feel dumb to ask because I bet this is a simple question... Looking at the code below, can someone please explain why I get two different values in my Marshal.SizeOf calls (see the commented...
3
by: Erik H. | last post by:
I have an ASPX page in which I am trying to bind a datagrid to a dataset pulled from Microsoft Access DB using code inline method. For some reason, the compiler is having a problem with 'using'....
5
by: Lyle Avery | last post by:
Hello guys, Look at this in c++ file: class T { public: char c; char ca; };
1
by: stromhau | last post by:
Hi, I have made a few classes in c++. They somehow cooperate doing some 3d stuff. Basically it is a moving camera acting as a flight, i have placed a lot of objects around the scene together with...
2
by: cr55 | last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
3
by: rajatamilarasu | last post by:
for(i=0 ; i<listNum ; i++) { checker.checkN1DisagreementSwitch(pRep_Active_SList.ChassisID, pRep_Active_SList.SlotID, pRep_Standby_SList.ChassisID, pRep_Standby_SList.SlotID); ...
1
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, Assuming I have a class/struct with only following types float, int, string what is the most efficient way to pack it to a single byte array before I send it out. I tried to use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.