如何将字符串传递给类中的方法?类和传递字符串作为方法的参数
代码
class Txtbin{
private:
std::string input;
std::string output = "output.png";
void error();
public:
Txtbin();
void run();
};
Txtbin::Txtbin(){
}
void Txtbin::error(const char* str){
throw std::runtime_error(str);
}
void Txtbin::run(){
if(input == ""){
error("Input file not defined");
}
}
错误
# g++ -std=c++11 txtbin.cpp -o txtbin `pkg-config opencv --cflags --libs`
txtbin.cpp:30:6: error: prototype for ‘void Txtbin::error(const char*)’ does not match any in class ‘Txtbin’
void Txtbin::error(const char* str){
^
txtbin.cpp:14:8: error: candidate is: void Txtbin::error()
void error();
^
你甚至读过吗? – LogicStuff
我是C++的新手,所以我不知道它是什么意思。也许你可以告诉我? – clarkk
你声明'void error();'但是定义'void Txtbin :: error(const char * str)'?? ' –