【发布时间】:2022-01-20 20:34:45
【问题描述】:
我在做一个大学项目,遇到了这个问题 -> 当我声明 bool a 并在其中存储值 true/false 时,代码运行良好 但是虽然我只声明并在之后存储值,就像在代码中一样,但它显示了一个错误,谁能解释它为什么......?
#include <iostream>
class Design{
public:
void welcome(){
std :: cout << "------------------------------------------------------------\n";
std :: cout << " Welcome to Faculty Feedback form. Enter Your credentials\n";
std :: cout << "------------------------------------------------------------\n";
}
};
class Admin: public Design{
};
class Student: public Admin{
};
class Login: public Student{
//bool a = true; Works fine
bool a;
a = true; // Shows error
public:
void authenticate(){
}
};
int main(){
Login LOGIN;
LOGIN.welcome();
LOGIN.authenticate();
return 0;
}
【问题讨论】: