6 years, 1 month ago.

Classes

Can anyone, please, explain to me in layman's terms what is a Class, what are its parts(objects, constructors, etc.), how does it work, what goes into what file (cpp, h, main)...PLEASE? Im completely new in programming, but i am a mechatronics student and this is a big part of my education. The professor knows his stuff, but has zero knowledge delivery ability. If anyone knows a good text , a video tutorial or even by your own words, I would be more than grateful. Thank you people.

Best regards Domagoj

1 Answer

6 years ago.

Hi there,

The following documents should be helpful in understanding what C++ objects, classes, and header files are:

Here's the Mbed OS Quick Start to help you get started programming with Mbed OS: https://os.mbed.com/docs/latest/tutorials/mbed-os-quick-start.html

In regards to what goes into what files:

  • main.cpp - This is the main file that is run first by the program. For beginner users, your main.cpp file will look similar to main file in the Mbed OS example Blinky:

#include "mbed.h"

DigitalOut led1(LED1);

// main() runs in its own thread in the OS
int main() {
    while (true) {
        led1 = !led1;
        wait(0.5);
    }
}
  • You'll want to put the code that your program will run inside of the int main() { } brackets (like above).
  • Make sure to have #include "mbed.h" at the top of the file so you can use the functions and variables provided to you by Mbed OS.

Please let me know if you have any questions!

- Jenny, team Mbed

Accepted Answer