fatcoder
Member
|
Improved STRUCT
Grzegorz, in defines.h you have the following for extending a struct.
Code:
#define STRUCT( Extended, Base) struct Extended : Base { PLATFORM(, typedef Base super;)
#define STRUCT_PRIVATE(Extended, Base) struct Extended : private Base { PLATFORM(, typedef Base super;)
The only problem is, these defines only allow you to specify one base class, so they don't work when you need to extend with two or more base classes.
If possible, can you use something like this, which allows extension with one or more base classes.
Code:
#define STRUCT( Extended, ...) struct Extended : __VA_ARGS__ { PLATFORM(, typedef __VA_ARGS__ super;)
#define STRUCT_PRIVATE(Extended, ...) struct Extended : private __VA_ARGS__ { PLATFORM(, typedef __VA_ARGS__ super;)
I've only been using these on Windows, so not sure if VA_ARGS is available on other platforms. Also not 100% sure of the effect on the super on iOS, or whichever platform it is that requires this. Anyway, might be worth using if you find it works across all platforms.
|
|
01-25-2013 07:48 AM |
|
Esenthel
Administrator
|
RE: Improved STRUCT
you can't do something like that
typedef __VA_ARGS__ super;
you can't do typedef to multiple classes at once
If you want to extend multiple classes I suggest doing this the normal way:
struct A : B, C, D
{
};
|
|
01-25-2013 12:16 PM |
|
Zervox
Member
|
RE: Improved STRUCT
if I misunderstood you Greg, it is possible, or did you mean not for all platforms?
Code:
#define STRUCT( Extended, ...) struct Extended : __VA_ARGS__ { PLATFORM(, typedef __VA_ARGS__ super;)
#define STRUCT_PRIVATE(Extended, ...) struct Extended : private __VA_ARGS__ { PLATFORM(, typedef __VA_ARGS__ super;)
STRUCT(Base,Game::Chr,Game::Item)
};
(This post was last modified: 01-25-2013 11:35 PM by Zervox.)
|
|
01-25-2013 11:34 PM |
|
fatcoder
Member
|
RE: Improved STRUCT
The super typedef isn't used for Windows (from what I understand), so perhaps VS just ignores this (i.e. no warnings).
Let me make a slight adjustment. This lets you control the super, by using the first class.
Code:
#define STRUCT( Extended, Base, ...) struct Extended : Base, __VA_ARGS__ { PLATFORM(, typedef Base super;)
#define STRUCT_PRIVATE(Extended, Base, ...) struct Extended : private Base, __VA_ARGS__ { PLATFORM(, typedef Base super;)
Again I'm not sure how this affects the super for other platforms. The super typedef is only used by iOS or Mac, is that right?
|
|
01-25-2013 11:50 PM |
|
Esenthel
Administrator
|
RE: Improved STRUCT
The point of super is to be able to access a member of any base class. Proposed method will only use super for first class. So you will have different behavior on windows and non windows compilers which I want to avoid.
The best way to have super on all four platforms is to use code editor which does some magic to make it work everywhere
|
|
01-26-2013 12:13 PM |
|
fatcoder
Member
|
RE: Improved STRUCT
Thanks, but I'll stick with visual studio. I tried the code editor a couple of times and got too frustrated as it lacks all the many features I've become accustomed to in visual studio. Not sure what "magic" the code editor is doing, but super already works correctly in visual studio, exposing all inherited base classes. Mind you, I only compile for Windows anyway.
|
|
01-27-2013 12:13 AM |
|
Esenthel
Administrator
|
RE: Improved STRUCT
Please let me know what features do you miss in Code Editor from Visual Studio.
If you compile only for windows then you don't need STRUCT at all
|
|
01-27-2013 12:44 PM |
|