Я пытаюсь воспроизвести пример ConstexPR из книги Stroustrup «Язык программирования C ++» 4th Ed, стр. 265-266. Я использую сообщество Visual Studio 2022. Приведенный ниже код не компилируется с сообщением < /p>
error C2662: 'Point Point::up(int)': cannot convert 'this' pointer from 'const Point' to 'Point &'
1\> Conversion loses qualifiers
< /code>
struct Point {
int x, y, z;
constexpr Point up(int d) { return { x,y,z + d }; }
};
int main()
{
constexpr Point p{1, 2};
p.up(1);//fails here, no problem if constexpr is removed on the line above
return 0;
}
< /code>
Would be grateful for a diagnosis and explanations
Подробнее здесь: https://stackoverflow.com/questions/794 ... -vs-c-2022
Книга Stroustrup Book Contexpr Пример не компилируется в VS C ++ 2022 ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение