Question

I have a C++ File class with read function, that is supposed to read whole contents of a file (just like Python does) into a buffer. However, when I tried to call read function from unistd.h, I get:

file.cpp:21: error: no matching function for call to ‘File::read(int&, char*&, int)’

file.cpp:17: note: candidates are: char* File::read()

What am I doing wrong? These have completely different signatures, why can't I simply call it?

Was it helpful?

Solution

Have you tried being explicit about scope;

char* File::read()
{
   // Double-colon to get to global scope
   ::read(...);
   // ..
}

?

OTHER TIPS

The definition for the posix standard version of the read method is defined as extern "C". This is neccesary so that the read symbol is not mangled by the C++ compiler and links against the proper function in the library. Mixing and matching C and C++ symbols will have unpredictable results. If possible, rename the c++ function so as not to conflict with any symbols that are declared extern "C".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top