GodProbablyExists
GodProbablyExists

Reputation: 83

How to change struct parent variables from declaration?

struct Movement {
  int left = 0;
  int right = 0;
};

struct TurnLeft : Movement {
  left = 200; 
  right = MAX_SPEED;
};

I want TurnLeft to override left and right. How?

Upvotes: 0

Views: 54

Answers (1)

Vittorio Romeo
Vittorio Romeo

Reputation: 93324

There's no way of doing this without a constructor. Example:

struct Movement {
  int left = 0;
  int right = 0;
};

struct TurnLeft : Movement {
  TurnLeft() : Movement{200, MAX_SPEED} { }
};

live example on wandbox

Upvotes: 6

Related Questions