+ 1
Is it possible to use structs in classes and if so, how?
In case anyone was wondering, structs are basically like classes but they can only hold data types and variables. I tried putting a struct into a class but I could not make use of it. So is this possible, or is it all just a pipe dream.
13 Respuestas
+ 2
If you're talking about C++, struct behaves exactly like class, you can use inheritance, declare functions, etc. The only difference is that struct default access modifier is public, while class is private.
Though, I'm not sure I understand your question, whether you're talking about defining a struct inside a class, or having a struct as one of the class member. Either way, both are possible
+ 2
Mike The great Sage
Like I said, it's possible and it's the same like having class as member in another class
Example:
struct SomeStruct {
...
};
class SomeClass {
...
private:
SomeStruct str;
};
+ 2
Will try this thank you
+ 2
Thank you swim , that really helped a lot.
+ 1
Thank you for clarifying the abilities of structs, my main question is how would someone go about making and using structs as a member of a class. Would it be the same as making a class a member or would it be different from a class.
+ 1
Ok, understood. Thank you for really clearing things up. Much appreciated.
+ 1
Struct could be a class member but not inherited. Right?
+ 1
Found this, but most of the content has already been expressed already in this thread.
https://stackoverflow.com/questions/3574040/c-can-a-struct-inherit-from-a-class
+ 1
Thanks for your input sonic
+ 1
Sonic
Thanks!