我创建了一个类,并且在该类中,我使用一个函数将标准时间转换为军事时间,现在我正尝试在该类中的另一个函数中使用该函数。但是每次我尝试编译时,它的返回值都未在此范围内声明。
这是我的主要内容:
int main(int argc, char const *argv[]) {
ifstream in ;
string appData ;
vector<Appointment> agenda ;
vector<Appointment> temp ;
in.open("agenda.txt") ;
if(in.fail()){
cout << "file error" << endl ;
}
while(!in.eof()){
getline(in, appData) ;
if(!appData.empty()){
agenda.push_back(appData) ;
}
}
in.close() ;
if(strcmp(argv[1], "-ps") == 0){
psFunc(agenda, temp) ;
}
}
这是我的.cc
文件,其函数返回错误:
void psFunc(vector<Appointment> mainVector, vector<Appointment> temp){
int cmpr = 0 ;
string temp1 ;
string temp2 ;
while(mainVector.size() != temp.size()){
for(size_t i = 0; i < mainVector.size(); i++){
temp1 = mainVector.at(cmpr).getTime() ;
temp2 = mainVector.at(i).getTime() ;
if(standardToMilitary(temp1) < standardToMilitary(temp2)){
continue ;
} else if(standardToMilitary(temp1) > standardToMilitary(temp2)){
cmpr = i ;
}
}
temp.push_back(temp1) ;
mainVector.erase(mainVector.begin() + cmpr) ;
}
cout << "Date" << setw(8) << "Title" << setw(30) << "Time" << setw(10) << "Duration" ;
cout << "----------------------------------------------------------------------------------------" ;
for(size_t j = 0; j < temp.size(); j++){
cout << temp.at(j).getDate() + " " + temp.at(j).getTitle() << endl ;
}
}
这里是standardToMilitary()
:
int Appointment::standardToMilitary(string time){
//reads the line for an A or a for AM and the opposite for PM, it then substr to find the hours/minutes and compiles a string
string militaryT ;
int returnTime ;
nospaces(time) ;
// this section is for times with single digit hours
if(time.length() == 6){
if(time.substr(4, 1) == "A" || time.substr(4, 1) == "a"){
militaryT += time[0] ;
militaryT += time.substr(2,2) ;
returnTime = stoi(militaryT) ;
} else if(time.substr(4, 1) == "P" || time.substr(4, 1) == "p"){
militaryT += time[0] ;
militaryT += time.substr(2,2) ;
returnTime = stoi(militaryT) + 1200 ;
}
}
// this section is for times with double digit hours
if(time.length() == 7){
if(time.substr(0,2) == "12" && (time.substr(5,1) == "A" || time.substr(5,1) == "a")){
militaryT += time.substr(3,2) ;
returnTime = stoi(militaryT) ;
} else if(time.substr(0,2) == "12" && (time.substr(5,1) == "P" || time.substr(5,1) == "p")){
militaryT += "12" ;
militaryT += time.substr(3,2) ;
returnTime = stoi(militaryT) ;
} else if(time.substr(5, 1) == "A" || time.substr(5, 1) == "a"){
militaryT += time.substr(0,2) ;
militaryT += time.substr(3,2) ;
returnTime = stoi(militaryT) ;
} else if(time.substr(5,1) == "P" || time.substr(5,1) == "p"){
militaryT += time.substr(0,2) ;
militaryT += time.substr(3,2) ;
returnTime = stoi(militaryT) + 1200 ;
}
}
return returnTime ;
}
我的程序是从文件中读取行,将其转换为Appointment
类中的对象,然后将所有对象放入vector
中。 psFunc
应该按时间重新排列vector
的顺序,而我正在尝试使用standardToMilitary()
函数比较时间,然后寻找最早的时间并将它们push_back()
变成另一个vector
。
答案 0 :(得分:2)
您的select orderdate as MonthsSales, Highestrevenue, Lowestrevenue
from
(select to_char(orderdate, 'Month') orderdate, max(orderfinalprice) as Highestrevenue
, min (orderfinalprice) as Lowestrevenue
from hologicOrder_T
group by to_char(orderdate, 'Month'))
order by monthsales;
是一个非静态的成员函数,因此它需要一个对象实例来调用它:
standardToMilitary
如果要在没有对象的情况下调用它,则使其成为独立函数(将其移到类定义之外),或在类中将其声明为Appointment a;
//...
a.standardToMilitary(/*...*/);
。