大家好,我正在做一个项目,直到我撞墙之前,我的表现都不错。我遇到两个错误:错误:未在此范围内声明“ binarySearch”错误:未在此范围内声明“ addInOrder”这是我的文件,我尝试了很多尝试都没有用。帮助将不胜感激。直方图#include "histogram.h"#include "countedLocs.h"//#include "vectorUtils.h"#include <string>#include <vector>using namespace std;void histogram (istream& input, ostream& output){ // Step 1 - set up the data vector<CountedLocations> countedLocs; // Step 2 - read and count the requested locators string logEntry; getline (input, logEntry); while (input) { string request = extractTheRequest(logEntry); if (isAGet(request)) { string locator = extractLocator(request); int position = binarySearch (countedLocs, CountedLocations(locator, 0)); /** Hint - when looking CountedLocations up in any kind of container, we really don't care if the counts match up or not, just so long as the URLs are the same. ***/ if (position >= 0) { // We found this locator already in the array. // Increment its count ++countedLocs[position].count; } else { // This is a new locator. Add it. CountedLocations newLocation (locator, 1); addInOrder (countedLocs, newLocation); } } getline (input, logEntry); } // Step 3 - write the output report for (int i = 0; i < countedLocs.size(); ++i) output << countedLocs[i] << endl;}countedLocs.cpp#include "countedLocs.h"#include <iostream>#include <vector>using namespace std;int CountedLocations::binarySearch(const vector<CountedLocations> list, CountedLocations searchItem){ //Code was here}int CountedLocations::addInOrder (std::vector<CountedLocations>& vectr, CountedLocations value){ //Code was here}countedLocs.h#ifndef COUNTEDLOCATIONS#define COUNTEDLOCATIONS#include <iostream>#include <string>#include <vector>struct CountedLocations{ std::string url; int count; CountedLocations (){ url = ""; count = 0; } CountedLocations(std::string a, int b){ url = a; count = b; } int addInOrder (std::vector<CountedLocations>& vectr, CountedLocations value); int binarySearch (const std::vector<CountedLocations> list, CountedLocations searchItem);};inlinestd::ostream& operator<< (std::ostream &out, CountedLocations& cL){ //out << "URL: " << cL.url << " count: " << cL.count << std::endl; out << "\"" << cL.url << "\"," << cL.count; return out;}#endif 最佳答案 这些方法是CountedLocations的成员方法...使用something.extractLocator和something.binarySearch或使histogram()成为CountedLocations的成员方法...(something的类型为CountedLocations很有可能是)关于c++ - C++错误:未在范围中声明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19962311/ 10-09 13:26