Resolving a linker error: undefined reference to static class members

后端 未结 4 1249
甜味超标
甜味超标 2020-12-21 03:31

My code is Arduinoish. I turned on verbose compiling so I could verify that all the .o files are indeed getting passed to the linker correctly, and they are (linker command

4条回答
  •  感情败类
    2020-12-21 04:16

    Because the value _serial is static, it exists when an object isn't instantiated. This means that you must declare it in the code as

    NewSoftSerial SerialServoControl::_serial(9, 8);
    char SerialServoControl::_tx = 0;
    char SerialServoControl::_rx = 0;
    

    which has already been suggested.

    If you then want to change it in the init function, you simply have to change your _serial = ... line to SerialServoControl::_serial = NewSoftSerial(tx, rx). Of course, this means you'll have to define a relevant constructor for the NewSoftSerial class.

    Hope this helps.

提交回复
热议问题