Код: Выделить всё
typedef struct T {
int val;
} T;
void test(volatile T*p, T a) {
*p = (volatile T)a; // doesn't work for G++
*p = a; // doesn't work for G++
}
Код: Выделить всё
: In function 'void test(volatile T*, T)':
:29:22: error: ambiguous overload for 'operator=' (operand types are 'volatile T' and 'volatile T')
29 | *p = (volatile T)a; // doesn't work for G++
| ^
:24:16: note: candidate: 'constexpr T& T::operator=(T&&)' (near match)
24 | typedef struct T {
| ^
:24:16: note: conversion of argument 1 would be ill-formed:
:29:10: error: binding reference of type 'T&&' to 'volatile T' discards qualifiers
29 | *p = (volatile T)a; // doesn't work for G++
| ^~~~~~~~~~~~~
:24:16: note: candidate: 'constexpr T& T::operator=(const T&)' (near match)
24 | typedef struct T {
| ^
:24:16: note: conversion of argument 1 would be ill-formed:
:29:10: error: binding reference of type 'const T&' to 'volatile T' discards qualifiers
29 | *p = (volatile T)a; // doesn't work for G++
| ^~~~~~~~~~~~~
:30:10: error: passing 'volatile T' as 'this' argument discards qualifiers [-fpermissive]
30 | *p = a; // doesn't work for G++
| ^
:24:16: note: in call to 'constexpr T& T::operator=(const T&)'
24 | typedef struct T {
|
Любые предложения будут оценены
[Изменить]
Я следую предложению @Some программиста, чувак
Чтобы это было возможно, функция должна быть объявлено с
самым квалификатором изменчивости: T&operator=(T const&) Volatility;
Код: Выделить всё
typedef struct T {
int val;
T& operator=(const T &a) volatile {
val = a.val;
return const_cast(*this);
}
} T;
void test(volatile T*p, T a) {
*p = (volatile T)a; // doesn't work for G++
*p = a; // doesn't work for G++
}
Код: Выделить всё
:15:8: error: no viable overloaded '='
*p = (volatile T)a; // doesn't work for G++
~~ ^ ~~~~~~~~~~~~~
:8:8: note: candidate function not viable: 1st argument ('volatile T') would lose volatile qualifier
T& operator=(const T &a) volatile {
^
Подробнее здесь: https://stackoverflow.com/questions/740 ... en-c-and-c
Мобильная версия