我遇到以下输出的编译时错误:
$ 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);
Run Code Online (Sandbox Code Playgroud)
但是,我没有看到该错误是如何有意义的,因为我只有函数声明,我在编写定义时直接复制和粘贴.
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();
}
};
Run Code Online (Sandbox Code Playgroud)
你fileExists在课堂上有两次.没有定义
bool fileExists(const std::string & path);
Run Code Online (Sandbox Code Playgroud)
并且一旦确定
bool fileExists(const std::string & path)
{
std::ifstream file(path);
return file.good();
}
Run Code Online (Sandbox Code Playgroud)
您有两个选项可以删除无定义部分,或删除with定义部分并在类外提供定义.
| 归档时间: |
|
| 查看次数: |
8617 次 |
| 最近记录: |