error: 'nullptr' was not declared in this scope

e-onux
Posts: 1
Joined: Mon Dec 19, 2016 11:44 pm

error: 'nullptr' was not declared in this scope

Postby e-onux » Mon Dec 19, 2016 11:53 pm

I'm just writing some libraries. I need optional function pointer for user my library.
But it gives error on STM32duino. It was ok on Arduino UNO.

If you please give me a hand to sort out this problem.

Error is:

Code: Select all

Controller.h:30: error: 'nullptr' was not declared in this scope
     treat = nullptr;
             ^
'nullptr' was not declared in this scope


Thanks.

Code: Select all

/**
* Usage:

#include "Controller.h"


#define joyXPin A0

Controller joyX(joyXPin);
int joyXTreat(int data) {
  return ((data * 255 /  510) - 255) / 2 + 0.5;
}
joyX.treat = &joyXTreat;

loop(){
  int joyXValue = joyX.read();
}
*/
#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <stdio.h>
#include <Arduino.h>
#include "ResponsiveAnalogRead.h"

class Controller {
 
public:
  Controller(int controllerPin): analog(controllerPin, true) {
    treat = nullptr;
  }
 
  typedef int (*FunctionTreatValue)(int);
  static const FunctionTreatValue &treatDefault;
  FunctionTreatValue treat;
 
  int read() {
    analog.update();
    int value = analog.getValue();
    if(treat)
    return treat(value);
    else value;
  }
 
private:
  int ctrlPin;
  ResponsiveAnalogRead analog;
 
};
#endif

HexTank
Posts: 43
Joined: Fri Sep 30, 2016 10:46 am

Re: error: 'nullptr' was not declared in this scope

Postby HexTank » Fri Jan 06, 2017 12:10 pm

I would suspect that's down to the compiler, you could replace with NULL.

User avatar
Rick Kimball
Posts: 683
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: error: 'nullptr' was not declared in this scope

Postby Rick Kimball » Fri Jan 06, 2017 1:32 pm

nullptr is a c++11 feature, either turn that feature on --std=c++11 or just use 0 or NULL


Return to “Problems with libraries”

Who is online

Users browsing this forum: No registered users and 1 guest