我刚刚开始学习课程,而且我在使用我的主要成员函数来打印我想要的数据时遇到了困难。 这是我得到的错误:
main.cpp:在函数'int main()'中: 错误:请求'd'中的成员'printNumerical',它是非类型'Date(int,int,int)' d.printNumerical(); ^
错误:请求'd'中的成员'printMonth',它是非类型'Date(int,int,int)' d.printMonth(); ^
错误:在'd'中请求成员'printDateFirst',这是非类型'Date(int,int,int)' d.printDateFirst(); ^
这是我的主要内容:
int main ()
{
int Day, Month, Year;
cout << "date information: ";
cin >> Day;
cin >> Month;
cin >> Year;
cout << Day << " " << Month << " " << Year << endl;
Date d (int Day, int Month, int Year);
//where I am having issues
d.printNumerical();
d.printMonth();
d.printDateFirst();
return 0;
}
这是我的类定义Date.h
class Date
{
private:
int month,
day,
year;
public:
Date(int Day,int Month,int Year); //constructor
Date(); //constructor if not passed arguments
void printNumerical(); //functions to output in certain format
void printMonthFirst();
void printDateFirst();
};
这是Date.cpp
Date::Date()
{
month = 1;
day = 1;
year = 2001;
}
Date::Date(int Day, int Month, int Year)
{ //input validation
if((Month < 1) || (Month > 12) || (Day < 1) || (Day > 31) || (Year < 0))
{
month = 1;
day = 1;
year = 2001;
}
else{
month = Month; //accept passed arguments if valid
day = Day;
year = Year;
}
}
void Date::printNumerical()
{
cout << month << "/" << day << "/" << year << endl;
}
void Date::printMonthFirst()
{
switch(month)
{
case 1 : cout << "January ";
break;
case 2 : cout << "February ";
break;
case 3 : cout << "March ";
break;
case 4 : cout << "April ";
break;
case 5 : cout << "May ";
break;
case 6 : cout << "June ";
break;
case 7 : cout << "July ";
break;
case 8 : cout << "August ";
break;
case 9 : cout << "September ";
break;
case 10 : cout << "October ";
break;
case 11 : cout << "November ";
break;
case 12 : cout << "December ";
break;
}
cout << day << ", " ;
cout << year << endl;
}
void Date::printDateFirst()
{
cout << day << " ";
switch(month)
{
case 1 : cout << "January ";
break;
case 2 : cout << "February ";
break;
case 3 : cout << "March ";
break;
case 4 : cout << "April ";
break;
case 5 : cout << "May ";
break;
case 6 : cout << "June ";
break;
case 7 : cout << "July ";
break;
case 8 : cout << "August ";
break;
case 9 : cout << "September ";
break;
case 10 : cout << "October ";
break;
case 11 : cout << "November ";
break;
case 12 : cout << "December ";
break;
}
cout << year << endl;
}
答案 0 :(得分:0)
以下一行:
Date d (int Day, int Month, int Year);
实际上是函数的前向声明,它将三个整数作为输入并返回Date
个对象。
Date d (Day, Month, Year); // proper construction
答案 1 :(得分:0)
您的代码中出现此错误的原因是您以错误的方式对对象d进行了Decalred:
在main函数中,尝试用from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
runDriver = sys.argv[1]
sessionId = sys.argv[2]
def setBrowser():
if eval(runDriver):
webdriver = w.Remote(command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
)
else:
webdriver = w.Remote(command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
session_id=sessionId)
url = webdriver.command_executor._url
session_id = webdriver.session_id
print url
print session_id
return webdriver
替换Date d (int Day, int Month, int Year);
(或传递任何整数而不是这个)。
好吧,即使在那之后,我注意到你的程序中会有另一个编译时错误。您已调用Date d (1,1,2001);
(在main()中),该类在该类中不存在。我想你想打电话给d.printMonth()
。
我希望这能解决问题。祝你好运!