Accessing structs
-
- Average
- Posts: 61
- Joined: Thu Jun 03, 2010 3:53 pm
Accessing structs
Is there a way to declare a variable in one class as a struct from another, without one class being a subclass of another? The only way I can do it is by using a return value as part of an expression, which only works for reading a variable, but not for changing it (e.g. MyObject.GetStruct().Var1)
- Feralidragon
- Godlike
- Posts: 5493
- Joined: Wed Feb 27, 2008 6:24 pm
- Personal rank: Work In Progress
- Location: Liandri
Re: Accessing structs
Well, if I understood right your question, no you can't. When you define a struct in a class, you can use it as well in subclasses and even extend it to add more variables, but afaik you can't create a struct in one class and use that same struct in a totally different unrelated class.
You must understand that "structs" are actually pretty much the same thing as "classes", the difference is that you can instanciate an actual "class" and call functions from it, while a "struct" just holds "members" (variables) in it, and nothing more. But their hierarquy and heritage works the same like in an actual class.
What you can do is "replicate" the struct in the other class, and use functions to exchange data from one to another. May you post here the code of what exactly you want to do with those structs and how you were trying to achieve it?
You must understand that "structs" are actually pretty much the same thing as "classes", the difference is that you can instanciate an actual "class" and call functions from it, while a "struct" just holds "members" (variables) in it, and nothing more. But their hierarquy and heritage works the same like in an actual class.
What you can do is "replicate" the struct in the other class, and use functions to exchange data from one to another. May you post here the code of what exactly you want to do with those structs and how you were trying to achieve it?
-
- Average
- Posts: 61
- Joined: Thu Jun 03, 2010 3:53 pm
Re: Accessing structs
Yep, you did understand me right. Well, I'm fine with that, I can work with structs being subclass-only, it would have just made my hierarchy a bit tidier.
Cheers
Cheers