C++ struct vs Class in terms of memory [duplicate] - c++

This question already has answers here:
C/C++ Struct vs Class
(7 answers)
Closed 6 years ago.
I have recently come across a question in one of my interview.
What is the difference between C++ struct & class in terms of memory ??
I know they are same in all aspects except access specifiers while inheriting & in case of member variables.
Apart from this is there a real difference in terms of memory (may be memory allocation or destruction or memory management whatever) ????
Edit:
I am not pretty sure why did the interviewer asks this question when there is no difference. I have found similar question here see the 2nd comment down to that link, he is asking a same question but no answer. I think there should be a diff.
Thanks In Advance.

In C++, a class and a struct are completly identical except for the facts that structs default to public access and inheritance whereas class defaults to private.
As far as memory layout there is no difference what-so-ever.

Related

What is the seperate implementation interfact class idiom and when do I use it? [duplicate]

This question already has answers here:
Is the PIMPL idiom really used in practice?
(12 answers)
Closed 7 years ago.
I have occasionally come across what I can only describe as the "interface-implementation idiom", where a class is separated into an "interface class" and an "implementation class".
What is the philosophy or reasoning behind this?
What is an example usage of this methodology? What does an example of such a class system look like and why would it be useful to separate a class into an interface and an implementation?
I think what you're talking about is also known as the pImpl pattern. There is lots of discussion about it at Why Should the pImpl idiom be used. That question is also marked as a duplicate of an older question/answer with more information.

Why can struct in C++ do more things than in C? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
It seems to me that C++-style struct can do more things than a C-style struct (for example, you can have member functions and access specifiers). What's the design reason for this, considering we already have class in c++?
A real design example would be appreciated.
What's the design reason for this, considering we already have class in c++?
A few potential benefits I can image are:
Easier compiler implementation by being able to handle structs and classes in almost the same way.
More options for developers. For instance, being able to use structs as more than just POD types by adding basic things like constructors, while leaving classes for usages where for object-oriented design is used.
Being able to derive from structs in C-compatible headers of 3rd-party libraries to add on convenience features like constructors and member functions.
A real design example would be appreciated.
Using the third idea: The Windows headers define a struct called RECT. MFC provides a class CRect which derives from it and provides several useful methods, but it's still able to be used in place of a RECT whenever needed by the Windows API.
If you are asking for a "design reason" to allow members to be defaulted to public visibility, then this is easily justified: The legacy struct from C originally assumed all members were public, so defaulting to public would make it easier to port C code to C++ without heavy modifications to the original C code. It also makes it easier to share C header files with C++ code.
If you are asking why struct was extended in C++ to be allowed to have protected/private sections and methods, then this has more to do with what the inventor of C++ imagined to be the fundamental difference between a struct and a class from the point of view of a user of the language. The answer was ultimately made that fundamentally, there is really no difference whatsoever (save the default to public visibility).

What is an equivalent to instanceof in C++? [duplicate]

This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.
There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.

Most Common Mistake done/seen in C++ [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What C++ pitfalls should I avoid ?
What is the most common mistake in C/C++programming that you keep committing or see most of the people do? Being aware of it atleast subconsciously will increase my or anyone's chances of committing it.
Wrong memory management in all kinds of ways - new without delete, delete on the wrong pointer, unclear ownership of a pointer with resulting memory allocation / deallocation problems etc.

Why is the heap (as in where we put objects) called that? [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
What is the origin of the term “heap” for the free store?
Why is the heap called the heap? I mean the bit of memory which we dynamically allocate bits of.
I don't have a citation for this, but I've always believed it derives from "a place to put stuff; a bit like the stack only less organised".
A stack has strict rules about where you add and remove things, but a heap doesn't.