S
S
Sencis2019-04-02 17:20:18
C++ / C#
Sencis, 2019-04-02 17:20:18

How to access a struct inside a function?

Data packets containing longitude and latitude arrive at the port. The number of packets becomes known only after the arrival of the head packet (which comes first). The data needs to be written to the structure, where there are two arrays of longitude/latitude, but how to declare the size of the array in the structure, if it is unknown before the arrival of the head packet? If you put a struct in a function that accepts the size of arrays, how do you access that struct?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2019-04-02
@Userpc0101

If it's C++, then you need to use containers, like std::vector. Storing latitude and longitude in two parallel arrays is wrong from a design point of view. It is necessary to create a structure (class) Point, with two fields lat, lon. You need to store a list of these points. You can put this list in your structure as well.

R
res2001, 2019-04-02
@res2001

Get the header first, dynamically allocate the required amount of memory based on it, and pass the buffer to the receiving function. You can use std::vector for arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question