0

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?

2

1 Answer 1

0

you can use a lambda

for example:

change the signature of your outer func for receive a std::function:

void func(std::function<void(char*, int)>&& funcToCall)

and call it like this:

func([&dskfl](char* c, int i){ dskfl.write(c, i); });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.