Search code examples
c++shadowsunistd.h

Standard POSIX read shadowed by a read method with different signature


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?


Solution

  • Have you tried being explicit about scope;

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

    ?