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
How do I tokenize a string in c++?
Difference between delete and free.
What is a function in oop?
What is latest update of C++ ?
Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister
What is do..while loops structure?
How can virtual functions in c++ be implemented?
What is a driver program?
Explain the advantages of using friend classes.
Array base access faster or pointer base access is faster?
How the endl and setw manipulator works?
Comment on c++ standard exceptions?
Write a program that can take input from 3 to 8 and calculate the average?
what is data abstraction in C++?
I was a c++ code and was asked to find out the bug in that. The bug was that he declared an object locally in a function and tried to return the pointer to that object. Since the object is local to the function, it no more exists after returning from the function. The pointer, therefore, is invalid outside.