PROS gyroscope in class

I have a class that will contain all the information for the gyroscope, it is simplified below.


//gyro.h
class Gyroscope {
private:
  int port;
  Gyro gyroscope
public:
  void init()
  //all the other functions related to the gyro
};
extern Gyroscope gyro;

//_gyro.cpp
void Gyroscope::init(){
  port = 1;
  gyroscope = gyroInit(port, 0);
};
Gyroscope gyro;

//init.cpp
gyro.init();


Gyro does not name a type inside the class however it works fine when not initialized in the class. If I can fix this how would I go about doing so?

EDIT: code block formatting

What’s the error? Make sure that you are including all the needed header files (namely


main.h

) and all that. I’m doing something similar in my code, which may be of some use to you

All the correct header files were included (in this case


api.h

.)
The error was:


'Gyro' does not name a type

However for whatever reason restarting atom fixed it so problem solved?

EDIT: code formatting (I am very bad at this)

The linter may have stopped displaying the error, but that doesn’t mean it has been fixed necessarily-- the only way to know for sure would be to compile and test on a robot.

That being said, the code itself looks fine to me.

(PS: can I ask why you are using


init

instead of a constructor?)

I already checked and it does work on a robot. The reason I am not using a constructor function is because I simplified the code in this example. In the actual code I am using one.

Glad to hear it- it must have just been a hiccup with the linter.

Ah, that explains it then :slight_smile: