Wednesday, August 26, 2009

Differences between C++ Classes and Structs

Quoted from Ref:

Probably the most frequently asked interview question that I have received is one that explores the difference between C++ classes and structs. Such a question was asked by a Northrop Grumman recruiter during a career fair at UC Irvine. I was also asked this sort of question during an on-site interview at Heavy Iron Studios. Recently, it has been asked during a phone interview with Amazon.com.

My answer typically states that members of a class are private by default, whereas members of a struct are public by default. Inheritance between classes is also private by default, and inheritance between structs is public by default. The interviewer was usually satisfied with this answer, which Dr. Raymond Klefstad fed to my first computer science class. Lately, I was interested in the nontrivial cases that bring me uncertainty: a struct inheriting from a class and a class inheriting from a struct.

About Me

My photo
Jaison Paul Mulerikkal is the Vice Principal of Rajagiri School of Engineering and Technology (RSET), Kochi. He was the Principal of Jyothi Engineering College (JEC), Cheruthuruthy, Trissur, India. He is a member of CMI Sacred Heart Province, Kochi. He is a civil engineer by profession, but did his Masters in Information Systems from RMIT University, Melbourne, Australia and subsequently received his PhD in High Performance Scientific Computing from the Australian National University. He had worked as a computational scientist at the University of Auckland, New Zealand.