Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 16055

Redefinition of 'class xxx'

$
0
0

I know this was asked several times, but I read a lot of those discussions and could not figure out whats going on. For me it seems to be eater a limitation of c++ in arduino Ide or something I am missing. I did a very small test to show the error :

// main sketch
#include "tire.h"
#include "car.h"
Car c;
void setup() {
  // put your setup code here, to run once:
  Tire tire1;  tire1.tire_size = 2; tire1.tire_name = "front left";
  Tire tire2;  tire2.tire_size = 2; tire2.tire_name = "front right";  
  Tire tire3;  tire3.tire_size = 2; tire3.tire_name = "back left";
  Tire tire4;  tire4.tire_size = 2; tire4.tire_name = "back right";
  c.set_tires( tire1 , tire2 , tire3 , tire4 );
  c.car_type=1; c.car_name="toyota";
}
void loop() { }
// car.h
#include "car.h"
void Car::set_tires(Tire _tire1,Tire _tire2,Tire _tire3,Tire _tire4) {
  tire1=_tire1; tire2=_tire2; tire3=_tire3; tire4=_tire4;
}
// car.h
#include "tire.h"
#include <Arduino.h>
class Car {
public:
  int car_type;
  String car_name;
  Tire tire1;
  Tire tire2;
  Tire tire3;
  Tire tire4;
  void set_tires(Tire _tire1,Tire _tire2,Tire _tire3,Tire _tire4);
};
// tire.h
#include <Arduino.h>
class Tire {
public:
  int tire_size;
  String tire_name;
};

Why I get error ? What could I do to make classes programing to work ?

5 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 16055

Latest Images

Trending Articles



Latest Images