11 years, 7 months ago.

Will C++11 standard be supported ?

Hi I am trying to use std::bind which is a part of C++11 standard. I want to reuse function with three different methods, by passing a method pointer to my function.

Here is the test case which does not compile because of that problem. Do you know other solution how to pass the method to function correctly ?

  1. include "ITG3200.h"
  2. include <iostream>
  3. include <functional>

Serial pc(USBTX, USBRX); ITG3200 gyro(p9, p10);

int sample(int (ITG3200::*pfn)(void)) { int x=0; int i; for(i=0;i<3;i++) { x = x+(gyro.*pfn)(); } return(x/4); }

int main() { Set highest bandwidth. gyro.setLpBandwidth(LPFBW_42HZ);

while (1) { pc.printf("\r%i, %i, %i\r\n", sample(std::bind(&ITG3200::getGyroX, gyro)), sample(std::bind(&ITG3200::getGyroY, gyro)), sample(std::bind(&ITG3200::getGyroZ, gyro))); } }

That's not how bind works. You function signature needs to be int sample(std::function<int (void)> fn)

posted by Eric Wieser 27 Mar 2014

1 Answer

6 years, 10 months ago.

Here we are, nearly 5 years later, January 2018, and still no C++11 std::function:

C++11 std::function code snippet MBED attempt

 #include <functional>  // C++ std::function, std::bind, and other cool C++11 features.  
 // MBed resolves header file <function>

...

 std::function <void(void)> functionPointer;
 // Error: Namespace "std" has no member "function" in "main.cpp", Line: 65, Col: 7"