Hello all,
This is my first post here, this board seems to contain interesting stuff regarding C++, that's why I subscribed into it.
Ok, let's go the problem...
I have a class with two methods into it:
floodLog
writeToLog
floodLog is intended to create threads that will execute the method writeToLog.
The problem is that I can't compile it, I'm receiving the following error:
"testing.cpp", line 54: Error: Cannot assign void*(Testing::*)(void*) to void*(*)(void*).
Below you can see the source code:
#include <iostream>
using namespace std;
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/stat.h>
#ifndef AIX
#include <sys/siginfo.h>
#endif
#if defined sun
#include <sys/statvfs.h>
struct statvfs info;
#elif defined HPUX11
#include <sys/vfs.h>
struct statfs info;
#elif defined AIX
#include <sys/vfs.h>
struct statfs info;
#else
#include <sys/mount.h>
struct statfs info;
#endif
#include <cLog.h>
#include <pthread.h>
const char *mpszFileVersion[] = {"a", "b"};
const char *mpszEnvironment[] = {"c", "d"};
char *SCCS_LONGVERSION ;
#define LOGLEVEL 4
class Testing
{
private:
cLog* m_Log;
pthread_t tid;
void* (*fPtr)( void* );
public:
Testing( );
~Testing( );
void floodLog( int nThreads );
private:
void* writeToLog( void* );
};
Testing::Testing( )
{
cout << "Called constructor of Testing...\n";
m_Log = new cLog("TESTING", LOGLEVEL, 5242880);
fPtr = writeToLog;
}
void* Testing::writeToLog( void* )
{
m_Log->Write( LOGLEVEL, "Another thread writting...\n" );
return NULL;
}
void Testing::floodLog( int nThreads )
{
int i = 0;
cout << "Flooding cLog class with " << i << " threads.\n";
for( i = 0; i < nThreads; i++ )
{
cout << "Created Thread: " << ( i + 1 ) << endl;
pthread_create( &tid, NULL, fPtr, NULL );
}
cout << "Finished flooding.\n";
}
int main( )
{
Testing test;
cout << "Now in main.\n";
test.floodLog( 10 );
return 0;
}
Thanks in advance,
Regards,
Caio.