【问题标题】:How to send an arrays from one class to another class如何将数组从一个类发送到另一个类
【发布时间】:2019-01-08 08:58:04
【问题描述】:

我有一个在方法内部有数组的类,有没有办法将这些数组发送到另一个类?

头等舱:

class getloop{
   public:
        string sendnumber;
        getloop() : sendnumber() {}
};

二等:

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;
    }};

谢谢。

【问题讨论】:

  • 请复制您的代码并将其粘贴到您的 SO 帖子中,以便人们可以在他们自己的系统上复制和测试它以帮助您解决问题。
  • ...此外,使代码变得可搜索
  • 很抱歉我已经编辑了我的帖子
  • 标记为不清楚。特别是“有没有办法将这些数组发送到另一个类?”不清楚 - 你是说对象吗?
  • 我的意思是我想创建一个新类并从另一个类访问数组

标签: c++ arrays class


【解决方案1】:

最简单的方法是在 Class 中创建一个返回指向数组的指针的函数。然后访问 main() 中的数组并将其发送给其他类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    相关资源
    最近更新 更多