aspose file tools*
The moose likes C / C++ and the fly likes from CPP : what is the difference between structure and class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "from CPP : what is the difference between structure and class" Watch "from CPP : what is the difference between structure and class" New topic
Author

from CPP : what is the difference between structure and class

rohit shekhar
Ranch Hand

Joined: Mar 05, 2010
Posts: 32
in c++, "the only difference between a class and a struct is that by default all members are public in a struct and private in a class. In all other respect, structures and classes are equivalent." for only this difference what is the need of class we can achieve everything using struct only i think...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

rohit shekhar wrote:for only this difference what is the need of class we can achieve everything using struct only i think...

Is this question about Java or not??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hi,

Doesn't see like a relevant post about SCJP.

Best Regards,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

Java doesn't have structs, only classes.

(And this question certainly does not have anything to do with SCJP, so I've moved it to a more appropriate forum for you).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
rohit shekhar
Ranch Hand

Joined: Mar 05, 2010
Posts: 32
can any one please say me is there any forum for CPP like this forum.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Well Rohit,

You might want to check this and this

Nothing is like javaranch, i can assure you.

Best Regards,
rohit shekhar
Ranch Hand

Joined: Mar 05, 2010
Posts: 32
ya java is awesome i love it... but for placement purpose i have to study c++ too.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Rohit,

hehe, keep digging for forum like javaranch for C++ and let me know also.

Best Regards,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

rohit shekhar wrote:what is the need of class we can achieve everything using struct only i think...


You could be right. Or perhaps not, I don't know. But let me also point out that you don't need a for-loop because you can do everything it does with a while-loop. And you don't need an addition operator because you can do everything it does with just a subtraction operator. This list could be extended considerably.
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 247
rohit shekhar wrote:in c++, "the only difference between a class and a struct is that by default all members are public in a struct and private in a class. In all other respect, structures and classes are equivalent." for only this difference what is the need of class we can achieve everything using struct only i think...

Well, long ago in ancient times, we C++ programmers had the coding convention of using C++ classes mostly for encapsulation and using C++ structs only for no encapsulation. So during design conversations, when we talk about structs we always knew we were discussing publicly accessible members. Classes would mean otherwise, where there would be some private members. Yes, technically C++ classes and structs were the same but the difference was in how they were used in the programming.


SCJP 6
Joseph Eagan
Greenhorn

Joined: Apr 19, 2011
Posts: 4

Paul Clapham wrote:
rohit shekhar wrote:what is the need of class we can achieve everything using struct only i think...


You could be right. Or perhaps not, I don't know. But let me also point out that you don't need a for-loop because you can do everything it does with a while-loop. And you don't need an addition operator because you can do everything it does with just a subtraction operator. This list could be extended considerably.


The problem with classes is, nothing except when you try to go back through or modify someone else work and they used classes. It can be a bit difficult. Using other data structures like structs can be a life saver and much easier to look over.

I had an instructor that worked on the NASA's J.U.N.O. project JUNO PROJECT He used nothing but data structures and against classes altogether.


You will die,
I will die a Marine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: from CPP : what is the difference between structure and class