Re: what about enum class ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4 December 2013 14:51, Graziano Servizi wrote:
>
> ///////// code
> # include <iostream>
> using namespace std;
>
> class First
> {public:
> enum class Alpha : bool {A=false, B=true};
> protected:
> Alpha alpha;
> First(Alpha b)
> {alpha = b;
> clog << "First's ctor set " << static_cast<bool>(alpha) << endl;}
> };
>
> class Second : First
> {
> protected:
> Alpha First :: alpha; // to reset from private

(In the class above First::alpha is public, not private.)

This syntax is no longer part of C++, you should do it like this instead:

using First::alpha;

> public:
> First :: Alpha; // to reset Alpha type as public

And like this instead:

using First::Alpha;

> Second(Alpha b) : First(b)
> {
> clog << "Second's ctor handles " << static_cast<bool>(b) << endl;
> }
> };
>
> class Third : Second
> {
> public:
> Alpha giveMe() // Alpha is recognized without scope resolution (by
> inheritance...)
> {// alpha should be inherithed from First, through Second...or NOT?
> clog << "Second :: giveMe returns " << static_cast<bool>(alpha) << endl;
> return alpha;}
> Third(Alpha b = Alpha :: A) : Second(b)
> {
> clog << "Third's ctor handles " << static_cast<bool>(b) << endl;
> }
> };
>
> int main( )
> {
> Third aaa;
> clog << "in main one finds " << static_cast<bool>(aaa.giveMe()) << '\n';
> }
> ////////// end code
>

I think what happens is G++ incorrectly creates a new member
Second::alpha, which is not the same as First::alpha, so giveMe
returns an uninitialized variable.

You should stop using access declarations and your code will work.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux