- 论坛徽章:
- 0
|
为了简化代码,我用一个IO函数封装fread和fwrite函数。是这样声明的.
ssize_t IO(char *ptr, size_t size, size_t nmemb, FILE *stream,
size_t (*op)(void *,size_t,size_t,FILE*));
可是在编译时出了一大堆错误信息。大致是这样的
cent.cpp: In method `ssize_t Cent::Write(char *, unsigned int, unsigned int, unsigned int)':
cent.cpp:18: no matching function for call to `Cent::IO (char *&, size_t &, size_t &, size_t &, size_t (& (const void *, unsigned int, unsigned int, FILE *))'
cent.cpp:507: candidates are: int Cent::IO(char *, unsigned int, unsigned int, unsigned int, size_t (*)(void *, unsigned int, unsigned int, FILE *))
想来是fwrite的函数声明与fread不同造成的.多了一个const
fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
在C++中请问这样的函数指针应该如何写. |
|