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

Ответы 6

  • вот что мне выводится
    • Автор:

      brentpyzs
    • 6 лет назад
    • 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();}
  • int main2() - это вообще что?
    • Автор:

      chester50
    • 6 лет назад
    • 0
  • приношу извинения, все работает, просто я сбрасывал кусок большой программы где было много операторов и я переобозначал main2,main3 и так далее
    • Автор:

      moses
    • 6 лет назад
    • 0
  • не делайте так лучше
    • Автор:

      scott
    • 6 лет назад
    • 0
  • Вы сами это пишите или что это за Q&A?Vector2 &operator=(const Vector2 &v2){    this->x = v2.x, this->y = v2.y, this->z = v2.z;    return *this;}
    • Автор:

      marcelo69
    • 6 лет назад
    • 0
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years