Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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 ?
- include "ITG3200.h"
- include <iostream>
- 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))); } }
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"
That's not how bind works. You function signature needs to be
posted by Eric Wieser 27 Mar 2014int sample(std::function<int (void)> fn)