2012-07-30 105 views
2

我得到一些我从未面对过的错误,我该如何解决它。是否有某种形式的错误声明是我所做的。C++ .h&.cpp文件 - 原型错误

感谢您的帮助!

在currency.h文件

public: 
    currencyConverter(); 
    void stringToUpper(string); 

我在currency.cpp文件功能

void currencyConverter::stringToUpper(string &s) 
{ 
    for(unsigned int l = 0; l < s.length(); l++) 
    { 
    s[l] = toupper(s[l]); 
    } 
} 

错误消息:

CLEAN SUCCESSFUL (total time: 132ms) 
g++ -c -g -Wall -I/opt/local/include main.cpp -o main.o 
g++ -c -g -Wall -I/opt/local/include currencyConverter.cpp -o currencyConverter.o 
currencyConverter.cpp:25:6: error: prototype for ‘void currencyConverter::stringToUpper(std::string&)’ does not match any in class ‘currencyConverter’ 
currencyConverter.h:25:9: error: candidate is: void currencyConverter::stringToUpper(std::string) 
make: *** [currencyConverter.o] Error 1 

问题解决:

解决方案是到.h文件

void stringToUpper(string &);而不是void stringToUpper(string);

+0

stringToUpper(string&s)(注意引用),但声明是stringToUpper(string)(不带引用)。它们必须匹配(更改为stringToUpper(string&)声明)。 – 2012-07-30 18:19:01

+0

谢谢你们!解决与安纳比斯先生的评论 – 2012-07-30 18:19:44

回答

6

您在stringToUpper的声明中忘记了&

+1

谢谢!我现在添加并成功构建。当时间限制到达时,你将被标记为答案。 – 2012-07-30 18:20:57