Answer the question
In order to leave comments, you need to log in
Pascal. Variables and arrays inside classes?
Good day. I'm doing a naval battle, I've screwed up on determining the destruction of the ship.
There is a field 10 by 10, there is an array that stores the number of live decks of each ship. These 2 arrays have to be passed to each class method as arguments, because it is not possible to pass them to the constructor and store them inside the class, the values of the arrays do not change
......
type test=class
a:array[1..10, 1..10] of integer;
b:array [1..10] of integer;
constructor Create(a:array[1..10, 1..10] of integer; b:array [1..10] of integer);
...
Answer the question
In order to leave comments, you need to log in
What is happening? Doesn't compile?
It doesn't compile due to a misunderstanding of the concept of type equivalence. Unlike in C, seemingly identical types are not equivalent! For equivalence, it is necessary that their chains type A = B;
lead to the same “ancestor”. There is an operator for this type
.
const
FieldSize = 10;
MaxShips = 10;
type
TField = record
cells : array [1..FieldSize, 1..FieldSize] of integer;
nLive : array [1..MaxShips] of integer;
end;
TGame = class
Field : TField;
constructor Create(const Field : TField);
end;
var
x : Test;
....
x.Create(a, b); // неверно!
x := Test.Create(a, b); // верно!
type
DaInt = array of integer;
procedure DoSomething1(var x : array of integer);
procedure DoSomething2(var x : DaInt);
If we are talking about PascalABC, then look at the documentation, it is a bit special.
If PascalABC.NET, then even more so, these are perverted lattices.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question