SongPart mtm::SongStructure::getPart(int index) const {
assert(index >= 0 && index < num_of_parts);
return song_parts[index];
}
const SongPart& mtm::Song::operator[](int index) const {
assert(index >= 0 && index < song_length);
return (song_format->getPart(index));
}
我得到的第二个函数从返回值这样的警告:返回参照临时C++
返回参考临时[默认启用]
如何解决这一问题?而且我不能改变每个函数的返回值!
你确实是需要改变getPart揭露,如果参考你想通过引用将它从SongPart :: operator []传递出去。 –
'getPart'应该可能返回'SongPart const&' –
您已排除正确的修复。为了提供不同的修复,请告诉我们更多关于为什么您不能更改每个功能的返回值。 –