未声明的标识符?我以为我定义了它 [英] Undeclared identifier? I thought I defined it
本文介绍了未声明的标识符?我以为我定义了它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我在我的约会类的成员函数中遇到了一个未声明的标识符错误,发生了.我以为我在构造函数中初始化了这些变量,并在初始化列表中初始化了日期对象.但是这两个变量都不起作用.我只是有点困惑为什么编译器认为它是未声明的类型而不是变量.
So, I'm getting an undeclared identifier error in my member functions for my appointment class, occurs_on . I thought I initialized those variables in the constructor and the date object in the initializer list. But neither of the variables work. I'm just a bit confused why the compiler thinks it's an undeclared type and not a variable.
谢谢.
#include<iostream>
#include <string>
using namespace std;
class Date{
public:
Date(int month, int day, int year);
int getMonth() const;
int getDay() const;
int getYear() const;
private:
int month;
int day;
int year;
};
Date::Date(int month, int day, int year) {
this->month = month;
this->day = day;
this->year = year;
}
int Date::getMonth() const{
return month;
}
int Date::getDay() const{
return day;
}
int Date::getYear() const{
return year;
}
class Appointment
{
public:
Appointment(string description, int month, int day, int year, int hour, int minute);
virtual bool occurs_on(int month, int day, int year);
private:
int hour, minute;
string convertInt(int number) const;
virtual string print();
protected:
Date getDate();
Date date;
};
Appointment::Appointment(string description, int month, int day, int year, int hour, int minute):date(month, day, year){
// the above line, i'm trying to initalize the date object with the three parameters month day and year from the appointment constructor.
this-> hour = hour;
this-> minute =minute;
}
bool occurs_on(int month, int day, int year){
if (date.getMonth()== month && date.getYear()= year && date.getDay()==day) //first error. variables like hour and minute from the constructor and date from the initalizer list are giving me unknown type name errors. I thought I initalized those variables in the constructor and in the initalizer list.
day= minute; //
return true;
}
推荐答案
您在 occurs_on
前面错过了 Appointment::
.
You have missed Appointment::
in front of occurs_on
.
//---vvvvvvvvvvvvv
bool Appointment::occurs_on(int month, int day, int year){
// ..
}
这篇关于未声明的标识符?我以为我定义了它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文