RobLoach / raylib-cpp

C++ Object Oriented Wrapper for raylib
https://robloach.github.io/raylib-cpp/
zlib License
630 stars 79 forks source link

No operator matches these operand types: Vector2 += Vector2 #252

Closed Vanny-Chuck closed 1 year ago

Vanny-Chuck commented 1 year ago

image Are these operators pre-defined or am I doing something wrong? Here is my code if it helps:


#include "raylib.h"
#include "raymath.h"
#include <algorithm>

using namespace std;
int main(void)
{
    InitWindow(800, 450, "raylib [core] example - basic window");
    SetWindowState(FLAG_VSYNC_HINT);
    while (!WindowShouldClose()){
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawFPS(10,10);
        EndDrawing();
    }

    CloseWindow();

    return 0;
}        

class Particle {
    public:
        Vector2 pos;
        Vector2 vel;
        Vector2 acc;
        void Update() {
            vel += acc;
            pos += vel;
            acc -= acc;
        }
        void Show(Color c) {
            DrawCircle(pos.x,pos.y,5,c);
        }

};```
RobLoach commented 1 year ago

Hmmm, it might be because we added const to them? https://github.com/RobLoach/raylib-cpp/commit/9e8b4487c3988161f5406740638415f20a151562

Vanny-Chuck commented 1 year ago

I'll check stack overflow & see if anybody else has same prob. Thanks for responding so quick!

Vanny-Chuck commented 1 year ago

I am using C++ 17 (Default is 14 I think), maybe that might be changing something.

RobLoach commented 1 year ago

Mind running the tests? There's a test case for this over at: https://github.com/RobLoach/raylib-cpp/blob/master/tests/raylib_cpp_test.cpp#L26

Vanny-Chuck commented 1 year ago

I don't have

include "raylib-cpp.hpp"

and

include "raylib-assert.h"

perhaps this is the reason?

Vanny-Chuck commented 1 year ago

I just realized I've been using the C-based one. Sorry for the trouble.

Vanny-Chuck commented 1 year ago

Still having problems. Here is my code:


#include "C:\Users\super\OneDrive\Desktop\raylib-cpp-master\raylib-cpp-master\include\raylib-cpp.hpp"
#include "raylib.h"
int main() {
    int screenWidth = 800;
    int screenHeight = 450;

    raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");

    SetTargetFPS(60);

    while (!window.ShouldClose())
    {
        BeginDrawing();

        window.ClearBackground(RAYWHITE);

        // raylib
        Vector2 position = { 50, 50 };
        Vector2 speed = { 10, 10 };
        position.x += speed.x;
        position.y += speed.y;

        // raylib-cpp
        raylib::Vector2 position(50, 50);
        raylib::Vector2 speed(10, 10);
        position += speed; // Addition assignment operator override.

        EndDrawing();
    }

    return 0;
}```
RobLoach commented 1 year ago

What error do you run into? Looks like in this example, you're declaring position twice. You'll want either the raylib C example there, or the raylib-cpp example there.

Vanny-Chuck commented 1 year ago

Oh my gosh, for some reason I tried it today & it worked!(yes i was declaring it twice, but that wasn't what the error was about.)