Как инициализировать ptype2
для копирования структуры ptype3
(тип-преобразование)?Копировать конструктор с разной структурой в C++
typedef struct PType2 {
double x, y;
PType2() : x(0), y(0) {}
PType2(const PType3 & ptype3) : x(ptype3.x), y(ptype3.y) {} //Abort ptype3.z to create a two-dimensional point
PType2(double xy) : x(xy), y(xy) {}
PType2(double x, double y) : x(x), y(y) {}
} ptype2;
Выход:
error C2065: 'ptype3' : undeclared identifier
error C2143: syntax error : missing ',' before '&'
error C2228: left of '.a' must have class/struct/union
error C2228: left of '.b' must have class/struct/union
error C2664: 'PType2::PType2(const PType2 &)' : cannot convert argument 1 from 'ptype3' to 'const int'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
У меня есть два typedef struct
, ptype2(double x, double y)
и ptype3(double x, double y, double z)
.
Перегрузка оператора присваивания может решить проблему?
'PType2 (const PType3 & ptype3)' не является конструктором копирования. –
Был ли «PType3» определен перед «PType2»? – CoryKramer
Какой компилятор вы используете? Почему вы пытаетесь запустить комментарий с помощью '#'? Как определяется «PType3»? – skyking