Page 1 of 1

Posted: Tue Jan 08, 2002 12:28 pm
by asyukri10
Hi,
Another help plz... How to send a function/module as parameter? I know to do it in C but how in C++? :|

My code(C),

#include <stdio.h>

void print(char* s)
{
printf("Print = %s",s);
}
//------------------------------------

void process(void(*k)())
{
(*k)("C++ or C?n");
}
//------------------------------------

void main()
{
process(print);
}
//------------------------------------


Visual C++ error if written as C++ code(.cpp),

--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
d:rubishdfcpp1.cpp(11) : error C2197: 'void (__cdecl *)(void)' : too many actual parameters
d:rubishdfcpp1.cpp(16) : error C2664: 'process' : cannot convert parameter 1 from 'void (char *)' to 'void (__cdecl *)(void)'
None of the functions with this name in scope match the target type
Error executing cl.exe.

Cpp1.exe - 2 error(s), 0 warning(s)

Posted: Sun Jan 20, 2002 10:42 am
by asyukri10
void process(void(*k)(char*))
{ (*k)("C++ or C?n"); }
//------------------------------------

Posted: Sat Mar 23, 2002 10:14 am
by PMNOX
i didn't know that it is possible