如何将结构数组传递给C ++ [英] How to pass array of structures to function in c++

查看:75
本文介绍了如何将结构数组传递给C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将结构数组传递给一个函数,我这样来做:
这是我的功能

I need to pass array of structures to a function and I make it this way:
it's my function

void ShowRoutes(Route *routeList, int n, string title) { //... }

它是函数调用

ShowRoutes(routeList, n, "Unsorted list: ");

但是我想知道还有其他方法可以将结构数组传递给函数吗?

but I would like to know are there other ways to pass array of structures to function?

推荐答案

我知道将数组传递给函数的两种方法.

Two ways I know of to pass arrays to functions.

您的拥有方式:

void ShowRoutes(Route *routeList, int n, string title) { //... }

void ShowRoutes(Route routeList[], int n, string title) { //... }

以任何一种方式编写函数,您仍将以相同的方式调用它:

Either way you write the function, you would still call it the same way:

ShowRoutes(routeList, n, "Unsorted list: ");

但是正如其他人所提到的,学习std :: array和std :: vector是一个好主意.

But as others mentioned, would be a good idea to learn std::array and std::vector.

这篇关于如何将结构数组传递给C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆