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;
}
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();
}
#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
не делайте так лучше
Новые вопросы
Геометрия,
2 года назад
Математика,
2 года назад
Информатика,
8 лет назад
Математика,
8 лет назад
Алгебра,
9 лет назад