I am using G++ mostly and nowadays Visual Studio 2015. I wanted to build my project with VC++2015 but I get error messages that saying invalid use of '::' in a function given default arguments with a forward declared strongly typed enum.
Here is some code:
class Foo final
{
public:
Foo() {}
virtual ~Foo() {}
//! Forward declaration of Bar
enum class Bar : short;
//! "Faulty" function with default argument
void DoSmth(Bar aBar = Bar::Baz)
{
// ... code ...
}
//! Complete declaration of Bar
enum class Bar : short
{
Baz
};
protected:
private:
};
It gives me the error at the declaration of the function DoSmth() with the default argument Bar::Baz.
With G++ (tested with 4.9 and 5.1) the code compiles just fine but with VC++2015 it doesn't.
Im fully aware that I have to declare something before usage but. Is it just because that VC++2015 does not look within the scope of the class for the complete declaration and definition of Bar but G++ does? Or maybe does G++ just take the complete declaration and "merges" it with the forward declaration (as they are in the same scope) and thus makes it completely available to the class? Or maybe I am just plain wrong and something complete different causes this?
I can live with it that I have to change all my declarations for strongly typed enums in order to make it work with VC++2015.
But I also want to know why this is?
I am happy for all answers!
Aucun commentaire:
Enregistrer un commentaire