'显示i未在此范围内声明问题:ARRAY of OBJECT.
#include<iostream>
using namespace std;
class employee{
char name[30];
float age;
public:
void getdata();
void putdata();
};
void employee::getdata()
{
cout<<"Enter name"<<endl;
cin>>name;
cout<<"Enter the age "<<endl;
cin>>age;
}
void employee :: putdata()
{
cout<<"Name "<<name<<endl;
cout<<"age "<<age<<endl;
}
const int size=3;
int main()
{
employee manager[size];
for(int i=0;i<size;i++)
{
cout<<"manager details"<<i+1<<endl;
manager[i].getdata();
}
cout<<endl;
{
for(int i=0;i<size;i++)
cout<<"manager details"<<i+1<<endl;
manager[i].putdata();//main problem is here
}
return 0 ;
}`
这里是错误MSG的链接https://cpphelp4-u.blogspot.com/2021/10/array-of-object-error-msg-picture-link.html
#include<iostream>
using namespace std;
class employee{
char name[30];
float age;
public:
void getdata();
void putdata();
};
void employee::getdata()
{
cout<<"Enter name"<<endl;
cin>>name;
cout<<"Enter the age "<<endl;
cin>>age;
}
void employee :: putdata()
{
cout<<"Name "<<name<<endl;
cout<<"age "<<age<<endl;
}
const int size=3;
int main()
{
employee manager[size];//size?
for(int i=0;i<size;i++)
{
cout<<"manager details"<<i+1<<endl;//i+1??
manager[i].getdata();//i?
}
cout<<endl;
for(int i=0;i<size;i++)
{ //PROBLEM WAS HERE ,
cout<<"manager details"<<i+1<<endl;
manager[i].putdata();
}
return 0 ;
}