mam sobie wzorzec:
template<typename T>
class MojaKlasa
{
public:
...
PodKlasa<T> &getX()const
{
PodKlasa<T>& result = x ; // tu mi wy wala błąd
return result ;
}
bool operator==(MojaKlasa<T> &other)
{
...
}
private:
PodKlasa<T> x ;
};
chcę, aby gettery zwracały referencje, nie wartości
dlaczego mi wywala błąd:
In file included from test/MojaKlasaTest.cpp:4:
src/MojaKlasa.h: In member function ‘PodKlasa<T>& MojaKlasa<T>::getX() const [with T = int]’:
test/MojaKlasaTest.cpp:31: instantiated from here
src/MojaKlasa.h:44: error: invalid initialization of reference of type ‘PodKlasa<int>&’ from expression of type ‘const PodKlasa<int>’
?