ARDUINO WITH OOP

Dear all

I create a class and create new object but it gets error

please advice

void setup() {

}

void loop() {
  
}

class Car{
 
  Car mycar = new Car();
  }

Classes end, like structs, with a semicolon.

but it gets error

Don't ever tell us what the error is - it keeps us sharp.

duinopad:

class Car{

Car mycar = new Car();
  }

I don't get that. What are you trying there? Create a instance of the class within the class itself? Doesn't sound reasonable.

Just giving the C++ compiler a work-out I think :slight_smile:

Dear all
thanks for the reply and advice
but still it is

void setup() {

}

void loop() {
  
}

class Car{
 
  Car mycar = new Car();
  };

The error shows

Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"

oop:11: error: field 'mycar' has incomplete type
field 'mycar' has incomplete type

What you’re trying to do doesn’t (to me or the compiler) make a lot of sense.

Anything returned by “new” is going to be a pointer to a (in this case Car), but even if you make “mycar” a pointer, I can’t see what you’re trying to achieve.