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
Solved

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

Posted on 2003-10-22
2
341 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
2 Comments
 
LVL 4

Accepted Solution

by:
n_fortynine earned 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

839 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