What Are The Differences Between A C++ Struct And C++ Class?

Answer Posted / nikhil upadhyay

The default member and base-class access specifiers are different.
This is one of the commonly misunderstood aspects of C++. Believe it or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifiers, member functions, overloaded operators, and so on. Some of them have even written books about C++. Actually, the C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base-class inheritance, and a class defaults to the private access specifier and private base-class inheritance. Getting this question wrong does not necessarily disqualify an applicant. Getting it right is a definite plus.
Saying, "I don't know" is definitely the wrong answer. I advance an unusual position about this. C++ programmers should at least believe that they know the differences, even when they are wrong about them. Getting it wrong is, therefore, right. You can explain the true difference in the interview and advance the programmer's knowledge. If they disagree vociferously, you have an opportunity to observe how they handle contentious debate when they are wrong and don't know it yet.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a constant? Explain with an example.

721


Which programming language should I learn first?

746


What does and I oop mean in text?

813


Which coding certification is best?

756


hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.

1717






Are there any special rules about inlining?

771


Why is it necessary to use a reference in the argument to the copy constructor?

829


How to delete array of objects in C++? Proof by C++ code for proper deletion

524


What is ios :: in in c++?

805


How do you find out if a linked-list has an end?

834


What flag means?

696


What is a volatile variable in c++?

957


What is doubly linked list in c++?

813


Explain the use of this pointer?

857


Which header file allows file i/o with streams a) fileio.h b) iostream.h c) fstream.h

853