I have a class that has arrays inside of a method, is there any way to send these arrays into another class?
first class :
class getloop{
public:
string sendnumber;
getloop() : sendnumber() {}
};
second class :
class runloop{
private:
getloop a;
public:
void showdata(){
int b;
std::istringstream (a.sendnumber) >> b;
float celcius[b], reamur[b];
for(int i=1; i<=b; i++){
cout<<"enter celcius - "<<i<<" = ";
cin>>celcius[i];
reamur[i] = 0.8*celcius[i];
}
system("cls");
cout<<"-----------------------------------"<<endl;
cout<<"| Tabel Konversi |"<<endl;
cout<<"-----------------------------------"<<endl;
cout<<"| Celcius | Reamur |"<<endl;
cout<<"-----------------------------------"<<endl;
for(int i=1; i<=b; i++){
cout<<"|"; gotoxy(8,i+4); cout<<celcius[i]<<"\370"; gotoxy(16,i+4); cout<<"|";
gotoxy(24,i+4); cout<<reamur[i]<<"\370"; gotoxy(34,i+4); cout<<"|";
cout<<endl;
}
cout<<"-----------------------------------"<<endl;
}
void inloop(const getloop & acceptloop){
a = acceptloop;
}};
thank you.
Easiest way is to make a function in Class which returns a pointer to the array. Then access the array in main() and sent it to other class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.