0
제 코드에 문제가 있습니다. 나는 포인터를 놓친 것 같지만 그것을 발견 할 수 없다.C2440 int를 int로 변환 할 수 없습니다.
다음은 클래스 내 코드입니다 :
template <class T, class U>
class KeyValue
{
private:
T _key;
U _value;
public:
KeyValue();
KeyValue(T key, U value)
{
this->_key = key;
this->_value = value
};
T GetKey() { return this->_key; }
U GetValue() { return this->_value; }
};
그리고 오류가 발생 : 그것은 당신에게 prvalue을 제공합니다 의미 값을 기준으로
template<class T, class U>
inline U & SparseArray<T, U>::operator[](T key)
{
for (std::list<KeyValue<T, U>>::iterator it = list->begin(); it != list->end(); it++)
{
if (it->GetKey() == key)
{
return it->GetValue();
}
}
return (list->insert(list->begin(), KeyValue<T, U>(key, U())))->GetValue();
}
같은 좌변 참조를 반환해야합니다. 여기서 설명한 내용만으로는 사용자가 문제를 재현하여 진단 할 수 없습니다. – Xirema
'inline U &'는 멤버가 반환한다고 주장하지만,'obj-> GetValue()'는 실제로 반환되는 것으로, 실제 구현에서는'U GetValue()'입니다. 가치. 'U'는 'U'가 아닙니다. – WhozCraig