Предмет: Информатика,
автор: iiigor
50 БАЛЛОВ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
нужно исправить программу перегрузки оператора =
#include
#include
using namespace std;
struct Vector2
{
int x, y, z;
Vector2()
{}
Vector2(int x, int y, int z): x(x), y(y), z(z)
{}
Vector2 operator = ( const Vector2 &v2)
{
return Vector2(this->x=v2.x,this->y=v2.y,this->z=0);
}
std::string ToString()
{
std::stringstream s;
s <<"(" << this->x << "," << this->y <<"," << this->z << ")";
return s.str();
}
};
int main2()
{
Vector2 v2(4, 5 ,6);
Vector2 v3;
v3=v2;
cout << v3.ToString();
}
Ответы
Автор ответа:
1
Вы сами это пишите или что это за Q&A?
Vector2 &operator=(const Vector2 &v2)
{
this->x = v2.x, this->y = v2.y, this->z = v2.z;
return *this;
}
Vector2 &operator=(const Vector2 &v2)
{
this->x = v2.x, this->y = v2.y, this->z = v2.z;
return *this;
}
clinteastwood2:
что не работает?
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
#include
using namespace std;
struct Vector2
{
int x, y, z;
Vector2()
{}
Vector2(int x, int y, int z): x(x), y(y), z(z)
{}
Vector2 &operator=(const Vector2 &v2)
{
this->x = v2.x, this->y = v2.y, this->z = v2.z;
return *this;
}
std::string ToString()
{
std::stringstream s;
s <<"(" << this->x << "," << this->y <<"," << this->z << ")";
return s.str();
}
};
int main2()
{
Vector2 v1(1, 2, 3);
Vector2 v2(4, 5 ,6);
Vector2 v3;
v3=v2;
cout << v3.ToString();
}
Похожие вопросы
Предмет: Немецкий язык,
автор: bemix130
Предмет: Геометрия,
автор: arinamartinova2007
Предмет: Русский язык,
автор: kikakima
Предмет: География,
автор: Алинаааа11
Предмет: Биология,
автор: алялисичкина2047