我正在调用我的构造函数,但是当我在它们进入之前计算值时,它们是正确的,当我在构造函数中计算值时,我会得到废话和空白。
功能:
Play parse(string toParse){
vector<string> tokens;
string play = toParse;
string oName, dName;
int x, quarter, minutes, down, yardstogo, startloc, playdesc;
for(int y=0; y<10; y++){
x = toParse.find(",");
tokens.push_back(toParse.substr(0,x));
toParse = toParse.substr(x+1);
}
stringstream convert(tokens[1]);
convert >> quarter;
convert.str(tokens[2]);
convert >> minutes;
convert.str(tokens[6]);
convert >> down;
convert.str(tokens[7]);
convert >> yardstogo;
convert.str(tokens[8]);
convert >> startloc;
playdesc = findPlay(tokens[9]);
cout << "quarter: " << quarter << endl << "oteam: " << tokens[4] << endl;
Play a(quarter, minutes, tokens[4], tokens[5], down, yardstogo, startloc, playdesc, play);
return a;
}
构造函数:
Play::Play(int m_quarter, int m_minutes, string oTeam, string dTeam, int down, int yardToGO, int startLoc, int playDesc, string wholePlay)
{
m_quarter = m_quarter;
cout << m_quarter << endl;
m_minutes = m_minutes;
oTeam = oTeam;
cout << oTeam << endl;
dTeam = dTeam;
down = down;
yardToGO = yardToGO;
startLoc = startLoc;
playDesc = playDesc;
wholePlay = wholePlay;
}
例如,函数说“季度:1 oteam:DAL”,而构造函数说“季度:-947800344 oteam:”。
谢谢。
#ifndef PLAY_H_INCLUDED
#define PLAY_H_INCLUDED
#include <string>
class Play
{
private:
int m_quarter;
int m_minutes;
std::string oTeam;
std::string dTeam;
int m_down;
int m_yardToGO;
int m_startLoc;
int playDesc;
std::string wholePlay;
public:
int getQuarter();
int getMinutes();
std::string getoTeam();
std::string getdTeam();
int getDown();
int getYard();
int getStartLoc();
int getPlayDesc();
std::string getwholePlay();
Play(int m_quarter, int m_minutes, std::string oTeam, std::string dTeam, int down, int yardToGO, int startLoc, int playDesc, std::string wholePlay);
~Play();
Play parse(std::string toParse);
std::string findPlay(std::string playDesc);
};
#endif // PLAY_H_INCLUDED