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();
}

Ответы

Ответ дал: clinteastwood2
0
Вы сами это пишите или что это за Q&A?

Vector2 &operator=(const Vector2 &v2)
{
    this->x = v2.x, this->y = v2.y, this->z = v2.z;
    return *this;
}
Ответ дал: iiigor
0
вот что мне выводится
Ответ дал: iiigor
0
полный текст должен быть таким?#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)
{
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();
}
Ответ дал: clinteastwood2
0
int main2() - это вообще что?
Ответ дал: iiigor
0
приношу извинения, все работает, просто я сбрасывал кусок большой программы где было много операторов и я переобозначал main2,main3 и так далее
Ответ дал: clinteastwood2
0
не делайте так лучше
Вас заинтересует