Errors, bugs, questions - page 2718

 
Sergey Dzyublik:

ArrayResize applied to different arrays.
Or do you want one array with a sequence of values a: 1, 2, 3, 4, 5, 6, 7, 8,... ?

One array. From your variant I saw the possibility of sequential ArrayResize.

 
fxsaber:

One array. From your variant I saw the possibility of sequential ArrayResize.

You can also increment default_a in the constructor, zeroing it to the desired value before ArrayResize.

 
Sergey Dzyublik:

You can also increment default_a in the constructor, resetting it to the required value before ArrayResize.

For a general task, you can't, because it's not a sequential value.

It's a pity that we have to drag in a static variable, and public as well. It looks crunchy.

 
fxsaber:

How do I create an array of structures where one of the fields is const?

Alternatively:

struct A
{
  const int a;
  
  A( const int i ) : a(i)
  {
  }
  
  A() : a( getDef() ) {}
  
  static int getDef()
  {
     static int n = 0;
     return sdefs[n++];
  }
};

int sdefs[] = {5, 100, 200, 150, 500};
 
Hello traders ! A situation has arisen. A few days ago I stopped receiving signal copying, although I was connected to a signal, everything was fine. The VPS was working. I logged into the terminal the day before yesterday and copying started immediately. Yesterday it was not copied again ( . As a result I missed profit ... Three days. I monitor the trade from my phone.
Anybody have any tips on why this may be happening?
 
Koldun Zloy:

As an option:

Thank you. After filling the array, you could do ArrayFree(::sdefs).

 
fxsaber:

How do I create an array of structures where one of the fields is const?

What you want is strange. Imho - structures are C entities, we should treat them as POD objects, passive, without constructors and other sugar. You can make a class with setter that contains structure, setter will not allow re-assignment. I think this is more correct from a design point of view.

 
Vict:

What you want is strange. Imho - structures are C entities, we should treat them as POD objects, passive, without constructors and other sugar. You can make a class with a setter that contains a structure, the setter will not allow re-assignment. I think this is more correct from a design point of view.

In my opinion, fields that will never (and should never) be changed after creation are logically prescribed const.

 
fxsaber:

In my opinion, fields that will never (and should never) be changed after creation, it is logical to write const.

Well, you also have a constructor. It's up to you, of course, but structures are C entities and the model is different - passive entities with external logic (functions).

 
Vict:

Well, they also stuck you with the constructor. It's up to you to decide, of course, but structures are C entities and the model is different - passive entities with external logic (functions).

Constructor only because you can't initialise a const field without it. Structure or class - doesn't make any difference. The main thing is to have an object.

Reason: