I have two questions.
-
I know it is possible to declare class objects in structs. But is it ethical to do that from design point of view?
-
In my scenario I have a structure with a 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 of 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 is this totally an unacceptable way to do that? Can you suggest some solution to this problem?
struct=class(except for default visibility).If you have a “huge number of members” you are probably doing something wrong, change your design, otherwise it becomes intractable.
It is absolutely fine to nest classes and / or structs, where it makes sense. For instance, it’s common to define nested classes for implementation details (so a
linked_listclass could have anodemember class).There’s no such thing as a “class object”, and it’s not clear what you mean by that.
Don’t use
memset– you probably don’t need it, just use normal constructors and assignment.Wrong, you can use it.