A
A
AiR_WiZArD2020-08-07 17:20:37
C++ / C#
AiR_WiZArD, 2020-08-07 17:20:37

How to cram a dimensionless array inside a dimensionless array?

I don't know if I'm doing it right, but the essence is this: there is an object on which X different blocks with engines can be fixed, while each block with engines has Y different engines. Since the values ​​are set in a separate file, it will not be possible to determine in advance. And taking the maximum is not very economical in terms of resources. Wrote the following structures:

//	Одиночный трастер
typedef struct
{
  sf::String textureLocation;		// Текстура объекта
  sf::Vector2f attachmentPoint;	// Точка крепления в px
  sf::Vector2f size;				// Размер объекта  в метрах
  float textureRotation;			// Ориентация текстуры
  float maxAngle;					// Максимальное отклонение при повреждении
  float thrust;					// Тяга трастера
  float specificImpulse;			// Удельный импульс трастера
} thrusterType;

//	Блок трастеров
typedef struct
{
  sf::String textureLocation;		// Текстура объекта
  sf::Vector2f attachmentPoint;	// Точка крепления в px
  sf::Vector2f size;				// Размер объекта
  float textureRotation;			// Ориентация текстуры

        // Информация о трастерах в составе блока
  thrusterType thrusters[];		

} thrusterMountType;

//	Информация об объекте
typedef struct
{
  sf::String textureLocation;		// Текстура объекта
  sf::Vector2f centerMass;		// Центр масс
  sf::Vector2f size;				// Размер объекта
  float textureRotation;
  float massDry;					// Сухая масса
  float massFuel;					// Масса топлива
  int n;
  
  // Информация о блоках трастеров в составе объекта
  thrusterMountType thrusterMount[];

} physicalObjectType;


But the compiler refuses to accept this, because it creates a two-dimensional dimensionless array. How can it be redone?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2020-08-07
@AiR_WiZArD

Use std::vector. This is an array that can be expanded while the program is running. This is usually a good choice over arrays in almost all cases. See push_back or resize methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question