Ok, I know my title is very unclear but I think part of the problem is that I don't know how to explain it clearly enough for Google to be useful.
Basically I have two functions:
SentenceData parseSingleSentence(std::string inputString)
{
SentenceData actualSentenceData;
actualSentenceData.transmitter = inputString.substr(1, 2);
actualSentenceData.format = inputString.substr(3, 3);
// Data fields run from first ',' (index 7) and the last 3 characters can be disregarded
std::stringstream ss(inputString.substr(7, inputString.length()-10));
std::string newDataField;
while (!ss.eof()) {
getline(ss, newDataField, ',');
actualSentenceData.dataFields.push_back(newDataField);
}
return actualSentenceData;
}
bool hasCorrectNumberOfFields(SentenceData sentenceData)
{
std::map<std::string, int>::iterator iterator = supportedFormats.begin();
while (iterator != supportedFormats.end())
{
if (sentenceData.format == iterator->first && int(sentenceData.dataFields.size()) == iterator->second) return true;
++iterator;
}
return false;
}
In my main(), I would like to run:
parseSingleSentence(inputString);
if (!hasCorrectNumberOfFields(actualSentenceData)) continue;
However, there is a clear problem - the compiler doesn't recognise that actualSentenceData will be returned after parseSingleSentence() is called.
The error is: 376:43: Use of undeclared identifier 'actualSentenceData'
I was originally expecting the compiler to recognise that the appropriate variable would be returned by the first function. When it threw up the error I quickly realised the problem but don't understand what the solution could be.
Is there a fix for this? I've spent several hours trying to find out what I've missed and don't know where to go from here.
I've searched on Google and Stack Overflow. Plus looked through several C++ websites, watched some tutorials, and my lectures from university.