2 arrays are created:

  1. Array of Card objects - tables with numbers.
  2. The main numbers of this array, in this case the power of two.

4 values ​​must be created. With objects it works, but not with numbers.

Code:

int* AllNumList; int Cmin=0, Cmax=0; void Game() { bool end = 0; int numOfIterations = 0; int maxNum = 1; while (maxNum <= Cmax) { numOfIterations++; maxNum = pow(2, numOfIterations); } numOfIterations--; maxNum = pow(2, numOfIterations); Card* card = new Card [numOfIterations +1]; AllNumList = new int [numOfIterations+1]; for (int i = 0; i <= numOfIterations;i++) { AllNumList[i] = pow(2, i); card[i].AddGenNumber(pow(2, i)); } } 

First loop iteration:

Screen shot

Last iteration:

Screen shot

Closed due to the fact that the essence of the question is not clear to the participants of AnT , Kromster , vmchar , 0xdb , aleksandr barakin on May 27 at 15:09 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Maybe you have AddGenNumber error in AddGenNumber ... you do not give its text. - Harry
  • Not exactly in it. And here in general class Card? It also works fine, as can be seen from the stack frame. - Alleksh _
  • As you can see from the screenshot, the array is assigned only 1 possible value. - Alleksh _
  • If creating a variable globally does not work. Inside the function it works. But I need a global variable. - Alleksh _
  • one
    It is not at all clear what the question is about. What is this "4 meaning should be created"? What kind of "logic" are we talking about? What is "triggered" and "non-triggered"? Write a question from scratch in order or delete it. - AnT

1 answer 1

You were deceived by the debugger. The fact is that from the point of view of the type system, AllNumList is not an array, but a pointer. And the pointer does not say how many elements it indicates. Usually, pointers point to one element - its debugger is shown to you.

Try to explicitly see AllNumList[1] , AllNumList[2] and AllNumList[3] in the debugger - there you will find all the numbers that are lost.

  • (since the question was raised - maybe the headline will be more appropriately written by someone?) - andreymal
  • @andreymal I tried, but IMHO, the question is of very low quality and here only the TS or Pavel Mayorov could brush it up to match the answer (make MCVE) - Kromster
  • @Kromster can not imagine how to comb it ... - Pavel Mayorov