0
class
    MAP[G]
create
    make

feature --attributes
    g_array: ARRAY[G]
    size:INTEGER

feature{NONE}
make
    do
        g_array.make_empty
           size:=0
    end

class
    MAP_TESTING

m: MAP[INTEGER]

create m.make
print(m.size)

The first class consist of an array and its size. When I tried to create an m object of ARRAY, nothing seems to be printing out when I put print(m.size). Am I instantiating the array correctly? Am I using the correct make function for ARRAY? Why isn't it printing anything?

---------------------------

class
    MAP[G]
create
    make

feature --attributes
    g_array: ARRAY[G]
    size:INTEGER

feature{NONE}
make
  --I left this blank
    end

class
    MAP_TESTING

m: MAP[INTEGER]

create m.make
print(m.size)

This actually works when I left the make blank. It prints out 0. But this is no good because obviously if I call other functions using the array in MAP, it won't work. I actually tried using other functions from the class ARRAY, but I got a compile error.

J0natthaaann
  • 555
  • 1
  • 6
  • 11
  • The code with `g_array.make_empty` triggers an exception `Feature call on void target` because `g_array` is not initialized. Therefore `print` statement is not executed at all. Correct code would replace the feature call on `g_array` with the creation instruction on `g_array` that would create an array object and then execute `make_empty` on it. – Alexander Kogtenkov Feb 23 '14 at 04:56

1 Answers1

2

The line to create the array in MAP should be:

create g_array.make_empty

And MAP_TESTING should be:

class
    MAP_TESTING
creation
    make
feature
    m: MAP[INTEGER]

    make
    do
        create m.make
        print(m.size)
    end
end

(Note that the print does not output a newline so the zero may easily be lost in the terminal.)

Arkku
  • 41,011
  • 10
  • 62
  • 84