Problem creating a simple class

25 Nov 2019

Hi everyone!

I'm new to mbed and i'm trying to create my first class on this platform. But the problem is, i don't understand how to do it. I tried something which don't work...

That's it :

Coordonnees.hpp

#ifndef __COORDONNEES_
#define __COORDONNEES_

#include "stdint.h"

class Coordonnees
{
    private : 
        int         _x;
        int         _y;
        int16_t         _angle;
        const int16_t   _maxX;
        const int16_t   _maxY;
        const int16_t   _minAngle;
        const int16_t   _maxAngle;
        
        bool            _depassementX;
        bool            _depassementY;
    
    public  :
        Coordonnees(int x, int y);
};

#endif

Coordonnees.cpp

#include "Coordonnees.hpp"

Coordonnees::Coordonnees(int x, int y){
    _x              =   x;
    _y              =   y;
    
    _angle          =   0;
    
    _maxX           =   300;
    _maxY           =   800;
    _minAngle       =   0;
    _maxAngle       =   360;
    
    _depassementX   =   false;
    _depassementY   =   false;
}
    

I think that i made everything like the Flasher example available on mbed... https://os.mbed.com/cookbook/Writing-a-Library But when i try to build it, i have this error :

<<quote>>Error: "Coordonnees::Coordonnees(int, int)" provides no initializer for in "Coordonnees.cpp", Line: 3, Col: 40<</quote>>

What am i doing wrong?

26 Nov 2019

For those const variable, you should initialize them by

Coordonnees::Coordonnees(int x, int y) : _maxX(300), _maxY(800), _minAngle(0), _maxAngle(360) {    
    _x              =   x;
    _y              =   y;
    
    _angle          =   0;
    
    _depassementX   =   false;
    _depassementY   =   false;
}
26 Nov 2019

Hi ,

it works! Thank you very much!

05 Dec 2019

hello bro