Solved

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

Posted on 2003-10-22
2
322 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

910 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now