File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

from CPP : what is the difference between structure and class

 
rohit shekhar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Doesn't see like a relevant post about SCJP.

Best Regards,
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
rohit shekhar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one please say me is there any forum for CPP like this forum.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Rohit,

You might want to check this and this

Nothing is like javaranch, i can assure you.

Best Regards,
 
rohit shekhar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya java is awesome i love it... but for placement purpose i have to study c++ too.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohit,

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

Best Regards,
 
Paul Clapham
Sheriff
Pie
Posts: 20169
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joseph Eagan
Greenhorn
Posts: 4
C++ Objective C Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic