Re: Use of the override keyword to improve code quality
Posted: Tue Jun 18, 2013 7:07 am
Right - after digging a little deeper i found:.
For Example in the class CCgUniform
virtual void update(const void* data, const SMaterial& material) const = 0 _IRR_OVERRIDE_;
the GCC compiler says
error: 'override' does not name a type
which is a bit confusing.
If i change it to
virtual void update(const void* data, const SMaterial& material) const _IRR_OVERRIDE_;
it says
... marked override, but does not override.
AHA! - because it's a base class and cannot override something.
But there is also CCgUniform1f (and more) which inherit from CCgUniform.
So the _IRR_OVERRIDE_ must go there!
The Problem with CCgMaterialRenderer is something else (i just found out).
Somehow the gcc compiler wants the "keyword" override BEFORE the '= 0' !
So if i change
virtual void OnUnsetMaterial() = 0 _IRR_OVERRIDE_;
to
virtual void OnUnsetMaterial() _IRR_OVERRIDE_ = 0 ;
it works.
If this is true, then you would need different macros for different compilers which you place at different positions in the source.
Like:
virtual void OnUnsetMaterial() _IRR_OVERRIDE_GCC_ = 0 _IRR_OVERRIDE_MSVC_ ;
As far as i know it's a bug in GCC and will be corrected (in CLANG it works).
Maybe for now it's easiest NOT to use it with GCC:
So just change it in irrTypes.h:
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 7)
#define _IRR_OVERRIDE_
#elif (_MSC_VER >= 1600 ) /* supported since MSVC 2010 */
#define _IRR_OVERRIDE_ override
#elif (__clang_major__ >= 3)
#define _IRR_OVERRIDE_ override
#else
#define _IRR_OVERRIDE_
#endif
Because 'override' is mainly a "help" to avoid errors and you probably develop the core engine with MSVC, there would be no disadvantages for the normal user who happens to like GCC. If you find errors with YOUR development environmont it should
be of ok for the rest of us.
For Example in the class CCgUniform
virtual void update(const void* data, const SMaterial& material) const = 0 _IRR_OVERRIDE_;
the GCC compiler says
error: 'override' does not name a type
which is a bit confusing.
If i change it to
virtual void update(const void* data, const SMaterial& material) const _IRR_OVERRIDE_;
it says
... marked override, but does not override.
AHA! - because it's a base class and cannot override something.
But there is also CCgUniform1f (and more) which inherit from CCgUniform.
So the _IRR_OVERRIDE_ must go there!
The Problem with CCgMaterialRenderer is something else (i just found out).
Somehow the gcc compiler wants the "keyword" override BEFORE the '= 0' !
So if i change
virtual void OnUnsetMaterial() = 0 _IRR_OVERRIDE_;
to
virtual void OnUnsetMaterial() _IRR_OVERRIDE_ = 0 ;
it works.
If this is true, then you would need different macros for different compilers which you place at different positions in the source.
Like:
virtual void OnUnsetMaterial() _IRR_OVERRIDE_GCC_ = 0 _IRR_OVERRIDE_MSVC_ ;
As far as i know it's a bug in GCC and will be corrected (in CLANG it works).
Maybe for now it's easiest NOT to use it with GCC:
So just change it in irrTypes.h:
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 7)
#define _IRR_OVERRIDE_
#elif (_MSC_VER >= 1600 ) /* supported since MSVC 2010 */
#define _IRR_OVERRIDE_ override
#elif (__clang_major__ >= 3)
#define _IRR_OVERRIDE_ override
#else
#define _IRR_OVERRIDE_
#endif
Because 'override' is mainly a "help" to avoid errors and you probably develop the core engine with MSVC, there would be no disadvantages for the normal user who happens to like GCC. If you find errors with YOUR development environmont it should
be of ok for the rest of us.