2012-07-30 66 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