Portál AbcLinuxu, 12. května 2025 06:49
class Screen: public Drawable { private: Graphics g; // ... public: Graphics & getGraphics() const { return g; //řádek č. 110 } };Jenže kompilátor si stěžuje:
Screen.h:110: error: invalid initialization of reference of type 'graphics::Graphics&' from expression of type 'const graphics::Graphics'
Proč? Kde mám chybu?
const
, takže nemůže vracet nekonstantní referenci na prvek třídy. Buď vracejte 'const Graphics&
' nebo tu metodu nedeklarujte jako konstantní.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.