Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++: function cannot be overloaded

Tags:

c++

c++11

I am encountering a compile time error with the following output:

$ g++ -ggdb `pkg-config --cflags opencv` -o `basename main.cpp .cpp` main.cpp StringMethods/StringMethods.cpp `pkg-config --libs opencv` -std=c++0x
In file included from main.cpp:2:0:
VideoFile.hpp:32:10: error: ‘bool VideoFile::fileExists(const string&)’ cannot be overloaded
     bool fileExists(const std::string & path)
          ^
VideoFile.hpp:15:10: error: with ‘bool VideoFile::fileExists(const string&)’
     bool fileExists(const std::string & path);

However, I do not see how that error makes sense, because I have only function declaration which I directly copied and pasted when writing the definition.

class VideoFile
{
private:
    std::string filePath;
    bool fileExists(const std::string & path);

public:

    VideoFile(const std::string & path)
        :filePath(path)
    {
        filePath = StringMethods::trim(path);
        if (!fileExists(filePath))
            throw std::runtime_error("The file: " + filePath + " was not accessible");
    }

    ~VideoFile() 
    {

    }

    bool fileExists(const std::string & path)
    {
        std::ifstream file(path);
        return file.good();
    }
};
like image 764
RedShirt Avatar asked Nov 28 '22 13:11

RedShirt


1 Answers

You can't both declare and define a member function inside the class definition.

(You even made the declaration private and the definition public.)

Either remove the declaration or move the definition outside of the class definition (I recommend the latter).

like image 86
molbdnilo Avatar answered Dec 12 '22 00:12

molbdnilo