m0_65112842 2022-05-16 14:59 采纳率: 93.8%
浏览 282
已结题

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条回答 默认 最新

  • 爱晚乏客游 2022-05-16 15:14
    关注

    编译错误看你的oj系统是否已经帮你实现好了头文件之类的,你只需要写好函数他去调用还是需要你完完整整的全部代码

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月3日
  • 已采纳回答 5月26日
  • 创建了问题 5月16日

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况