Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Distinction between struct and class - simple, but URGENT!!

Dear experts,

I'm a newbie in C++ and am wondering what's the difference, in detail, between a struct and a class, with some examples so that I know whats going on!

Thanks!
0
nicholaf
Asked:
nicholaf
1 Solution
 
n_fortynineCommented:
structs originate from C, and classes are not. A basic difference between them is that for a struct the default state for its members is public, and for a class this state is private. For ex:
struct A {
   int a; //a is public by default
  private:
   int b;
};

class B {
   int a; //a is private by default.
  public:
   int b;
}

you can use them interchangebly if you keep this in mind.
0
 
nicholafAuthor Commented:
n_fortynine, thanks so much!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now