I have two questions.
1. I know it is possible to declare class objects in structs. But is it ethical to do that from design point of view?
2. In my scenario I have a structure with huge number of member elements and I want to include a class object too. Here I have another question. If I memset() the whole struct the class handle is also reset. So, I check the size of the rest of the struct without the class object and subtract it while I call memset(), to get rid os this problem. (Please note that I am using STL class 'queue' here. And I cannot use sizeof() operator on the object, since it is not overloaded.)
But this is totally an unacceptable way to do that. Can you suggest some solution to this problem?
"But is it ethical to do that from design point of view?"
It's called "Object Association", and it depends on the design. Typically, object association is called the "Has-A" relationship.
"If I memset() the whole struct the class handle is also reset."
Do not use memset() on a non-POD type, because you'll trample over the virtual table (if it has one)
"And I cannot use sizeof() operator on the object, since it is not overloaded.) "
You cannot overload the sizeof() operator anyway, because the compiler requires its use internally, and overloading would break allocation (both stack and heap) requests. And yes, you can use sizeof() on:
- Expressions that yield a value
- Expressions that yield a type