Errors, bugs, questions - page 1586

 

Compilation error

class A { public:
        void operator[]( int i ) {}
};
class B { public:
        B() : a( new A ) {}
        ~B() { delete a; }
        A *a;
        void f() const { a.operator[]( 0 ); } //нормально
        void g() const { a[ 0 ]; }            //error: call non-const method for constant object
        void h() const { (*a)[ 0 ];           //error: call non-const method for constant object
};
 
Where "normal" is, there should be an error. The operator is defined, not as const.
 
Anton Zverev:
Where "normal" is, there must be an error. The operator is defined, not as const.
"Psychiatrist" gets a D today
 
A100:
'Psychiatrist' gets a D today
class A { public:
        void operator[]( int i ) const {} // const добавил
};
class B { public:
        B() : a( new A ) {}
        ~B() { delete a; }
        A *a;
        void f() const { a.operator[]( 0 ); } // нет ошибки
        void g() const { a[ 0 ]; }            // нет ошибки
};
 
Anton Zverev:
It's the desktop version of Five we're talking about. There's no air mode.
What's the terminal got to do with it?! You need to disable the internet on the computer, and the easiest action is to enable aeroplane mode. Or go to settings and disable the network adapter.
 
Anton Zverev:

Learn how to match

 
Karputov Vladimir:
What does the terminal have to do with it?! You need to disable the internet on the computer, and the easiest action is to switch on "On Plane" mode. Or go into settings and disable the network adapter.
Where's that mode in Win7?! I'm sorry, but I'm a very weak user.
 
Anton Zverev:
Where's that mode in Win7?! Sorry, but I'm a very weak user.
Win7? Don't know such :) .I have WIndows 10.
 
A100:
Learn to match.
I'd love to learn, but Google doesn't understand where I went wrong. Could you summarise the point of my misunderstanding? I see a compiler error in your example at the "normal" line. In my mind, the compiler should have blurted out.
 
Anton Zverev:
I'd love to learn, but Google doesn't understand ...
Real tough men don't ask Google, they ask the ash tree :))