Possible Duplicate:
Disabling “bad function cast” warning
I am attempting to wrap my brain around c++ function pointers. To keep my learning experience basic, I created a test function pointer example. Eventually, I would like to pass all-ready instantiated objects by reference so I can callback the object's method; however, for the sake of learning and understand, I would like to stick to the basics of c++ function pointers. I created a working example just using a .cpp file, but the part that I am not succeeding at is using function pointers in .cpp and .h. What am I not doing correctly to get my learning example to work successfully when using .cpp and .h files?
I created two files, exeCallback.h and exeCallback.cpp.
.h file
/*
File: exeCallback.h
Header file for exeCommand Library.
*/
#ifndef EXECALLBACK_H
#define EXECALLBACK_H
#include "mbed.h"
#include <map>
class exeCallback
{
public:
exeCallback();
void my_int_func(int x);
void (*foo)(int);
private:
};
#endif
.cpp file:
/*
File: exeCallback.cpp
Execute functions in other Sensor libraries/classes
Constructor
*/
#include "mbed.h"
#include "ConfigFile.h"
#include "msExtensions.h"
#include "cfExtensions.h"
#include "exeCallback.h"
exeCallback::exeCallback()
{
foo = &exeCallback::my_int_func;
/* call my_int_func (note that you do not need to write (*foo)(2) ) */
foo( 2 );
}
void exeCallback::my_int_func(int x)
{
printf( "%d\n", x );
}