I tried to create function that get pointer for the functions of binary file, write and read. Both of functions need get :
1)char* (on write function the char* mean from witch address write, and on read function char* mean , to witch address read)
2) int (on write address that meam how many wirte and on read function that mean how many read).
I want create function that get pointer for read/ write , but i get an error my code.
#include <iostream>
using namespace std;
#include <fstream>
void func(void(*funcToCall)(char*, int))
{
char * temp= "zzz";
funcToCall(temp, 3);
}
int main()
{
fstream dskfl;
dskfl.open("aa.txt", ios::out | ios::binary);
dskfl.close();
dskfl.open("aa.txt", ios::out | ios::in | ios::binary);
char ddd[]= "fffff";
dskfl.write((char*)ddd, 5);
dskfl.seekp(0);
func(dskfl.write);
dskfl.close();
}
i get error on line
func(dskfl.write);
Error 1 error C3867: 'std::basic_ostream<char,std::char_traits<char>>::write': function call missing argument list; use '&std::basic_ostream<char,std::char_traits<char>>::write' to create a pointer to member
why please?
fstream* instance = &dskfl;andvoid (fstream::*method)(char*, int) = &fstream::write;and then use(instance->*method)(char*, int)to call the method.