m0_65112842
2022-05-16 14:59
采纳率: 100%
浏览 73

C++在VS能正常运行但是OJ系统显示编译错误?

在VS能运行但是OJ编译错误了。为什么?愁死我了


```c++

#include<iostream>
using namespace std;
template<typename T>
class Vector
{
private:
    T x, y, z;
public:

    Vector(T a = 0.0, T b = 0.0, T c = 0.0) :x(a), y(b), z(c) {}
    Vector(const Vector& a)
    {
        this->x = a.x;
        this->y = a.y;
        this->z = a.z;
    }
    friend istream& operator>>(istream& is,  Vector& xa)
    {
        double a, b, c;
        std::cin >> a >> b >> c;
        xa.x = a;
        xa.y = b;
        xa.z = c;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Vector& a)
    {
        os << a.x << " " <<a.y << " " << a.z;
        return os;
    }
    friend Vector operator*(const double a, const Vector& b)
    {
        Vector c;
        c.x = a * b.x;
        c.y = a * b.y;
        c.z = a * b.z;
        return c;
    }
    friend Vector operator+(const Vector& a, const Vector& b)
    {
        Vector c;
        c.x = a.x + b.x;
        c.y = a.y + b.y;
        c.z = a.z + b.z;
        return c;
    }
    friend int operator==(const Vector& a, const Vector& b)
    {
        if (abs(a.x-b.x)<1e-10 && abs(a.y-b.y)<1e-10 && abs(a.z-b.z)<1e-10)
        {
            return 1;
        }
        else
        {
            return 0;
        }         
    }
};
int main()
{
    double a, b, c;
    std::cin >> a >> b >> c;
    Vector<double> v1(a, b, c), v2(v1), v4;
    double d;
    std::cin >> d;
    v4 = d * v1 + v2;
    std::cout << v4 << std::endl;
    Vector<double>  v;
    std::cin >> v;
    int flag = (v4 == v);
    std::cout << flag << std::endl;
    return 0;
}


```

1条回答 默认 最新

相关推荐 更多相似问题