1 | |
---|
2 | NameBlock Proj = [[ |
---|
3 | Class MiClase { |
---|
4 | Real a; |
---|
5 | Static MiClase New(Real valor) { |
---|
6 | MiClase new = [[ |
---|
7 | Real a = valor |
---|
8 | ]] |
---|
9 | }; |
---|
10 | Static MiClase New2(Real valor) { |
---|
11 | Proj::MiClase new = [[ |
---|
12 | Real a = valor |
---|
13 | ]] |
---|
14 | } |
---|
15 | } |
---|
16 | ]]; |
---|
17 | |
---|
18 | ////////////////////////////////////////////////////////////////////////////// |
---|
19 | // [1] Error en el constructor New: |
---|
20 | |
---|
21 | /* |
---|
22 | Proj::MiClase ej = Proj::MiClase::New(3); |
---|
23 | */ |
---|
24 | // ERROR: [57] Uso indebido de "=" en MiClase new |
---|
25 | |
---|
26 | // Se soluciona usando New2: |
---|
27 | Proj::MiClase ej = Proj::MiClase::New2(3); |
---|
28 | |
---|
29 | // Descripción del error: |
---|
30 | // Las clases definidas dentro de un NameBlock hay que usarlas |
---|
31 | // mediante su nombre completo... |
---|
32 | |
---|
33 | ////////////////////////////////////////////////////////////////////////////// |
---|
34 | // [2] Creación en un bucle: |
---|
35 | |
---|
36 | // Encontramos un error |
---|
37 | /* |
---|
38 | Set For(1, 10, Proj::MiClase (Real i){ |
---|
39 | Proj::MiClase::New2(i) |
---|
40 | }); |
---|
41 | */ |
---|
42 | // ERROR: [60] Declaración errónea en función de usuario Proj::MiClase (Real i) |
---|
43 | |
---|
44 | // Se soluciona citando la clase como NameBlock: |
---|
45 | Set ej2 = For(1, 10, NameBlock (Real i){ |
---|
46 | Proj::MiClase::New2(i) |
---|
47 | }); |
---|
48 | |
---|
49 | ////////////////////////////////////////////////////////////////////////////// |
---|
50 | // [3] Acceso en un bucle: |
---|
51 | |
---|
52 | // Encontramos un error |
---|
53 | /* |
---|
54 | Set EvalSet(ej2, Text(Proj::MiClase c) { |
---|
55 | ClassOf(c) |
---|
56 | }); |
---|
57 | */ |
---|
58 | // ERROR: [63] Declaración errónea en función de usuario Text (Proj::MiClase c) |
---|
59 | |
---|
60 | Set EvalSet(ej2, Text(NameBlock c) { |
---|
61 | ClassOf(c) |
---|
62 | }); |
---|
63 | |
---|
64 | // La clase del objeto dice ser "MiClase". ¿Debería decir "Proj::MiClase"?. |
---|
65 | |
---|
66 | ////////////////////////////////////////////////////////////////////////////// |
---|
67 | |
---|