C++ Fehler: Wurde nicht deklariert in den Anwendungsbereich
Hey Leute, ich bin an einem Projekt arbeiten und ich machte mich ziemlich gut, bis ich traf diese Wand..
Bin ich immer zwei Fehler:
Fehler: 'binarysearch-Methode' wurde nicht deklariert, in diesem Umfang
Fehler: 'addInOrder' wurde nicht deklariert, in diesem Umfang
Hier sind meine Dateien, die ich ausprobiert habe schon ein paar Sachen ohne Erfolg. Hilfe wäre sehr geschätzt werden.
histogram.cpp
#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);
};
inline
std::ostream& operator<< (std::ostream &out, CountedLocations& cL)
{
//out << "URL: " << cL.url << " count: " << cL.count << std::endl;
out << "\"" << cL.url << "\"," << cL.count;
return out;
}
#endif
Du musst angemeldet sein, um einen Kommentar abzugeben.
Methoden sind die Methoden der CountedLocations... verwenden
something.extractLocator
undsomething.binarySearch
oder machen diehistogram()
auch eine member-Methode CountedLocations... (something
ist der TypCountedLocations
hoch vielleicht wirdcountedLocs[position]
)Haben Sie eine freie Funktion
histogram
in dem Sie versuchen, verwenden Sie zwei member-FunktionenaddInOrder
undbinarySearch
. Um Sie zu nutzen, müssen Sie eine Instanz derCountedLocations
.Wenn es sich um eine Art von helper-Funktionen, die nicht davon abhängen, die tatsächliche
CountedLocations
Beispiel würde ich Sie in statischen Funktionen, wie hier (Sie benötigen lediglich zum ändern der Kopfzeile):Dann rufen Sie diese Funktion durch die Angabe der Art der Klasse:
Die Sie versuchen zu nennen, Mitglied Methoden einer Struktur ohne ein Objekt dieses Typs. Seltsam.
Müssen Sie schauen, was ein namespace ist.
Deklarieren Sie eine Klasse CountedLocations, so weit so gut. Aber dann Sie versuchen, verwenden Sie die member-Funktionen außerhalb der CountedLocations namespace, die offensichtlich nie zu arbeiten.
binarysearch-Methode ist eine member-Funktion der CountedLocations namespace. Wenn Sie anrufen möchten, die Funktion, die Sie haben, um ein Objekt zu erstellen, enthält einen Verweis auf die member-Funktion.
Ich weiß nicht, ob das Ihr problem löst, aber man sollte dies wissen, bevor Sie sogar versuchen, ein problem zu lösen.