"Undefined Reference" in the constructor of a C++ function

Asked

Viewed 266 times

2

I am creating a VS1838B name class that is composed by other instances.

This is the class header:

#ifndef INFRAREDRECEIVERVS1838B_H
#define INFRAREDRECEIVERVS1838B_H

#include "Arduino.h"
#include "IRremote.h"
#include "IRremoteInt.h"

class VS1838B{

public:
    //Construtor
    VS1838B(int pinoReceptorIR);

    //Atributos
    IRrecv _receptorIR;                   //Objeto do tipo IRrecv
    decode_results _bufferSinalRecebido;  //Objeto que armazena o sinal recebido
    int _pinoInput;

};


#endif  /* INFRAREDRECEIVERVS1838B_H */

This and the file . cpp

#include "Arduino.h"
#include "InfraRedReceiverVs1838b.h"
#include "IRremote.h"
#include "IRremoteInt.h"


//Construtor
VS1838B::VS1838B(int pinoReceptorIR)
:_receptorIR (pinoReceptorIR), _bufferSinalRecebido()
{
_pinoInput = 11;
}

I get the following error message when trying to instantiate the class.

Infraredreceivervs1838b.cpp:9: Undefined Reference to `Irrecv::Irrecv(int)'

This is the class header that no reference was found:

// main class for receiving IR
class IRrecv
{
public:
  IRrecv(int recvpin);
  void blink13(int blinkflag);
  int decode(decode_results *results);
  void enableIRIn();
  void resume();
private:
  // These are called by decode
  int getRClevel(decode_results *results, int *offset, int *used, int t1);
  long decodeNEC(decode_results *results);
  long decodeSony(decode_results *results);
  long decodeSanyo(decode_results *results);
  long decodeMitsubishi(decode_results *results);
  long decodeRC5(decode_results *results);
  long decodeRC6(decode_results *results);
  long decodePanasonic(decode_results *results);
  long decodeLG(decode_results *results);
  long decodeJVC(decode_results *results);
  long decodeSAMSUNG(decode_results *results);
  long decodeHash(decode_results *results);
  int compare(unsigned int oldval, unsigned int newval);

} 
;

Why the error message? How can I build a class that is instance attributes of other classes? I’m beginner and any help and welcome.

  • The definition of the class IRrecv is in which header file (.h)? It was included in the header (.h) of the class VS1838B?

  • The Irrecv class is in the same context as the Irremote. h

  • Are you sure you are linking in the final executable the obj file that contains the constructor definition?

  • The problem occurs at the time of linking your library or executable. The library or object that implements the class constructor IRrecv is not being linked to its final binary and this should be solved by configuring your project in the IDE used. If the class IRrecv was made by yourself what is missing is to implement the constructor.

1 answer

-1

Try to use:

In the class definition declares:

IRrecv* _receptorIR;                   //Objeto do tipo IRrecv
decode_results* _bufferSinalRecebido;  //Objeto que armazena o sinal recebido

And put the builder this way:

//Construtor
VS1838B::VS1838B(int pinoReceptorIR)
{
    _pinoInput = 11;
    _receptorIR = new IRrecv(pinoReceptorIR);
    _bufferSinalRecebido = new decode_results();
}

Do not forget to create the destructor and release the appropriate memories.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.