?
Solved

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

Posted on 2003-10-22
2
Medium Priority
?
375 Views
Last Modified: 2010-04-01
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
Comment
Question by:nicholaf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
n_fortynine earned 2000 total points
ID: 9604116
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
 

Author Comment

by:nicholaf
ID: 9604216
n_fortynine, thanks so much!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question