Using objects created in main in another class

hi, I'm trying to create 2 classes.

  1. motor- where I can declare motors
    2.Rmove(robot- move)- where I can write functions that will tell the motors how to move to create the movements I want.
    in short- I want to be able to use a motor object in Rmove class and write in the class "motor1.left();" (or any other public function from the motor library).
    at the end, in the main, I want to declare my 4 motors pins and tell the robot to move forward or any other direction without needing to tell each motor seperatly how to move in the main, but in the Rmove class.

motor.h:

#include <Arduino.h>
class motor {
  
  private:
    int pin1;
    int pin2;
    
  public:
    motor();
    motor(int pin1, int pin2);
    void init();
    void right();
    void left();
    void off();
};

motor.cpp:

#include "motor.h"
motor::motor(int pin1, int pin2) {
  this->pin1 = pin1;
  this->pin2 = pin2;
  init();
}
void motor::init() {
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  off();
}
void motor::right() {
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, LOW);
}
void motor::left() {
  digitalWrite(pin1, LOW);
  digitalWrite(pin2, HIGH);
}
void motor::off() {
  digitalWrite(pin1, LOW);
  digitalWrite(pin2, LOW);
}

Rmove.h

#include "motor.h"
class Rmove {
  
  private:
    motor motor1;
    motor motor2;
    motor motor3;
    motor motor4;
    
  public:
    Rmove(motor motor1, motor motor2, motor motor3, motor motor4);
    void forward();
    void backward();
    void left();
    void right();
    void leftTurn();
    void rightTurn();
    void off();
};

Rmove.cpp

#include "Rmove.h"
Rmove::Rmove(motor motor1, motor motor2, motor motor3, motor motor4) {
  this->motor1 = motor1;
  this->motor2 = motor2;
  this->motor3 = motor3;
  this->motor4 = motor4;
}
void Rmove::forward() {
  motor1.right();
  motor2.off();
  motor3.left();
  motor4.off();
  
}
void Rmove::backward() {
  motor1.left();
  motor2.off();
  motor3.right();
  motor4.off();
}
void Rmove::left() {
  motor1.off();
  motor2.right();
  motor3.off();
  motor4.left();
}
void Rmove::right() {
  motor1.off();
  motor2.left();
  motor3.off();
  motor4.right();
}
void Rmove::leftTurn() {
  motor1.right();
  motor2.off();
  motor3.right();
  motor4.off();
}
void Rmove::rightTurn() {
  motor1.left();
  motor2.off();
  motor3.left();
  motor4.off();
}
void Rmove::off() {
  motor1.off();
  motor2.off();
  motor3.off();
  motor4.off();
}

main:

#include "Rmove.h"
motor motor1(13,12);
motor motor2(11,10);
motor motor3(9,8);
motor motor4(7,6);
Rmove robot(motor1, motor2, motor3, motor4);
void setup() {
  
}
void loop() {
    motor1.right();
    delay(1000);
    motor1.left();
    delay(1000);
    motor1.off();
    delay(1000);
//    robot.forward();
//    delay(1000);
    
}

if I try to run the code without the "Rmove robot(motor1, motor2, motor3, motor4);" line in the main it runs without any problems but if I try with it, the compiler shouts at me it cant compile to arduino uno.
what am I doing wrong?

change to

class Rmove {
  
  private:
    motor& motor1;
    motor& motor2;
    motor& motor3;
    motor& motor4;
    
  public:
    Rmove(motor& motor1i, motor& motor2i, motor& motor3i, motor& motor4i) :
    motor1{motor1i}, motor2{motor2i}, motor3{motor3i}, motor4(motor4i) {}

drop

@Whandall it worked perfectly! I'm new to the OOP world, do you mind explaining please how did you fixed that?
in any way, thanks a lot!!

You tried to pass a copy of an object to the constructor, to be copied to a local object,
so you would have created three copies of each object,
one instance would have been deleted after the copy.

I used references to the external objects, but because references can't be assigned to,
I used the initialization list in the constructor to "copy" the reference.

Inside the containing class there is no syntactical change necessary as would have been,
had I used pointers to the external objects.

You don't want different objects controlling the same hardware, or do you?

ohh I get it now. thanks!