小编din*_*018的帖子

如何将structure/union数组的成员传递给函数

例如,我想显示结构/联合数组的一个成员的值,所以我想将它作为参数传递给一个只显示一个成员的函数,并且还将显示我作为参数传递的任何其他单个成员.

#include <iostream>
using namespace std;

union ThreeTypes
{
    char letter;
    int whole;
    double real;
};

void showArr(ThreeTypes[], int); // ?? What parameters to pass?

int main()
{
    const int SIZE = 50;
    ThreeTypes arr[SIZE];
    for (int i = 0; i < SIZE; i++)
        arr[i].real = 2.37;

    showArr(arr, SIZE, ??? ); // what argument to pass to display member?

    return 0;
}
void showArr(ThreeTypes arr[],int size,???) // also, what parameters??
{
    for (int i = 0; i < size; i++) …
Run Code Online (Sandbox Code Playgroud)

c++ c++17

0
推荐指数
1
解决办法
55
查看次数

标签 统计

c++ ×1

c++17 ×1