• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

from CPP : what is the difference between structure and class

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Doesn't see like a relevant post about SCJP.

Best Regards,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohit,

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

Best Regards,
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
Objective C C++ Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic