我不知道出了什么问题。我是c++的新手,但我看不出有什么问题。我已经阅读了一堆其他的堆栈溢出页面,但它们似乎都没有解决我的问题。
这是来自终端的
Joshs-MacBook-Pro:desktop Josh$ g++ BinaryCompare.cpp
BinaryCompare.cpp: In function ‘int main()’:
BinaryCompare.cpp:9: error: missing template arguments before ‘(’ token
这是代码。
#include <iostream>
#include <string>
using namespace std;
bool isGreater(string a, string b);
int main (){
if(greater("11", "00"))
cout << "hello"<<endl;
return 0;
}
bool isGreater(string a, string b){
if(a.length() > b.length() ) return false;
if(a.length() < b.length() ) return true;
for(int i= 0; i < a.length(); i++){
if(a[i] != b[i]){
if(a[i] == '1') return false;
return true;
}
}
return false;
}
发布于 2013-07-22 05:04:00
这就是为什么using namespace std
并不总是一个好主意的一个很好的例子。
你打错了
if(greater("11", "00"))
这确实应该是
if(isGreater("11", "00"))
...and设法达到你刚刚批发进口的a class template defined in the std
namespace的名字。从而产生令人困惑的错误消息。
发布于 2013-07-22 05:01:30
在if中,第9行上的greater()
应该替换为isGreater()
。
发布于 2013-07-22 05:03:38
除了修复在第9行调用isGreater
的greater
调用之外,您可能还希望确保用零填充字符串,直到两个字符串的长度相同,而不是只在isGreater
的前两行返回true
或false
。
https://stackoverflow.com/questions/17776850
复制相似问题