+運算符重載錯誤,即使它已重載

pan.h

#pragma once
#include "vector.h"

namespace math_ {
    
    void worldToScreen(const Vec2& world, Vec2& screen, const Vec2& offset);
    
}

pan.cpp

#include "pan.h"  
namespace math_{

    void worldToScreen(const Vec2& world, Vec2& screen, const Vec2& offset)
    {
        screen = world + offset;
    }

}

vector.h

#pragma once

namespace math_ {

    struct Vec2
    {
        Vec2(float x_, float y_);
        float x = 0.0f;
        float y = 0.0f;
        Vec2 operator +(const Vec2& other);
        Vec2 operator -(const Vec2& other);
    };

}

vector.cpp

#include "vector.h"

namespace math_ {

    Vec2::Vec2(float x_, float y_) :
        x(x_), y(y_) {}

    Vec2 Vec2::operator+(const Vec2& other)
    {
        return Vec2(this->x + other.x, this->y + other.y);
    }
}

vector.h包含在pan.h中,我試圖在函數worldToScreen中添加兩個向量,但是我得到了一個錯誤no operator + matches these operands,盡管它已在vector.cpp文件中重載。

我不認為這是重載本身的問題,因為當我試圖在一個文件中執行完全相同的操作時,文件中的所有內容都有效。只是當我試圖把東西分成不同的文件時,才發現有問題。一定是我做錯了什么,但我不知道是什么。

? 最佳回答:

重載未標記為const,但您是從const Vec2&調用它:

struct Vec2
{
    Vec2(float x_, float y_);
    float x = 0.0f;
    float y = 0.0f;
    Vec2 operator +(const Vec2& other) const;
    Vec2 operator -(const Vec2& other) const;
                                  //   ^^^^^
};

Vec2 Vec2::operator+(const Vec2& other) const
                                    //  ^^^^^
{
    return Vec2(this->x + other.x, this->y + other.y);
}
主站蜘蛛池模板: 伊人久久一区二区三区无码| 午夜福利一区二区三区在线观看 | 无码人妻久久久一区二区三区| 亚洲色精品VR一区区三区| 亚洲AV永久无码精品一区二区国产| 亚洲Av无码一区二区二三区| 国产免费无码一区二区| 国产成人高清亚洲一区91| 99久久无码一区人妻a黑 | 在线精品日韩一区二区三区| 亚洲一区二区三区91| 无码人妻精品一区二区三区夜夜嗨| 亚洲日韩国产一区二区三区 | 国产精品视频一区二区三区无码| 天码av无码一区二区三区四区| 午夜福利无码一区二区| 精品爆乳一区二区三区无码av| 无码成人一区二区| 无码精品人妻一区二区三区漫画 | 无码人妻精品一区二区三区久久| 中文字幕VA一区二区三区| 中文字幕在线观看一区二区 | 久99精品视频在线观看婷亚洲片国产一区一级在线 | 国产一区二区三区高清视频| 亚洲AV日韩精品一区二区三区| 一区二区三区四区在线观看视频| 国产一区二区三区免费在线观看| 国产天堂在线一区二区三区| 福利片免费一区二区三区| 日本一区二区三区不卡在线视频| 理论亚洲区美一区二区三区 | 在线|一区二区三区四区| 国产一区二区在线| 日本一区二区三区精品国产| 国产精品女同一区二区久久| 日本不卡在线一区二区三区视频| 亚洲福利视频一区| 精品亚洲福利一区二区| 爆乳熟妇一区二区三区霸乳| 精品一区二区久久| 无码人妻一区二区三区兔费|