compilation error

This is a discussion on compilation error within the Eiffel forums in Programming Languages category; I want to traverse a binary search tree and output each node-item. The following does not compile but I have no idea why not. The actual argument "v" has type INTEGER_32. See error message below. class APPLICATION create make feature -- Initialization make is -- Run application. local tree: MY_TREE [INTEGER] do create tree.make (500) tree.put (200) tree.put (100) tree.put (150) tree.put (125) tree.put (600) tree.put (550) tree.put (800) tree.put (700) tree.put (650) tree.put (750) tree.put (725) tree.i_infix end end -- class APPLICATION class MY_TREE [G -> COMPARABLE] inherit BINARY_SEARCH_TREE [G] redefine node_action end create make feature -- Cursor movement ...

Go Back   Application Development Forum > Programming Languages > Eiffel

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-18-2007, 05:32 AM
=?ISO-8859-1?Q?Roman_T=F6ngi?=
Guest
 
Default compilation error

I want to traverse a binary search tree and output
each node-item.
The following does not compile but I have no idea why not.
The actual argument "v" has type INTEGER_32.
See error message below.

class
APPLICATION
create
make
feature -- Initialization
make is
-- Run application.
local
tree: MY_TREE [INTEGER]
do
create tree.make (500)
tree.put (200)
tree.put (100)
tree.put (150)
tree.put (125)
tree.put (600)
tree.put (550)
tree.put (800)
tree.put (700)
tree.put (650)
tree.put (750)
tree.put (725)
tree.i_infix
end
end -- class APPLICATION


class
MY_TREE [G -> COMPARABLE]
inherit
BINARY_SEARCH_TREE [G]
redefine
node_action
end
create
make
feature -- Cursor movement
node_action (v: like item) is
-- Perfom action on item.
do
io.put_integer (v)
io.put_character (' ')
end
invariant
invariant_clause: True -- Your invariant here
end -- class MY_TREE



Error code: VUAR(2)
Type error: non-conforming actual argument in feature call.
What to do: make sure that type of actual argument conforms to type
of corresponding formal argument.

Class: MY_TREE [G -> COMPARABLE]
Feature: node_action
Called feature: put_integer (i: INTEGER_32) from STD_FILES
Argument name: i
Argument position: 1
Actual argument type: Generic #1
Formal argument type: INTEGER_32
Line: 32
do
-> io.put_integer (v)
io.put_character (' ')





Thanks a lot
Roman
Reply With Quote
  #2  
Old 10-18-2007, 06:36 AM
Friedrich Dominicus
Guest
 
Default Re: compilation error

Roman Töngi <roman.toengi@hispeed.ch> writes:

> I want to traverse a binary search tree and output
> each node-item.
> The following does not compile but I have no idea why not.
> The actual argument "v" has type INTEGER_32.
> See error message below.
>
> class
> APPLICATION
> create
> make
> feature -- Initialization
> make is
> -- Run application.
> local
> tree: MY_TREE [INTEGER]
> do
> create tree.make (500)
> tree.put (200)
> tree.put (100)
> tree.put (150)
> tree.put (125)
> tree.put (600)
> tree.put (550)
> tree.put (800)
> tree.put (700)
> tree.put (650)
> tree.put (750)
> tree.put (725)
> tree.i_infix
> end
> end -- class APPLICATION
>
>
> class
> MY_TREE [G -> COMPARABLE]
> inherit
> BINARY_SEARCH_TREE [G]
> redefine
> node_action
> end
> create
> make
> feature -- Cursor movement
> node_action (v: like item) is

this means like G
> -- Perfom action on item.
> do
> io.put_integer (v)

a G may or may not conform to an integer
> io.put_character (' ')
> end
> invariant
> invariant_clause: True -- Your invariant here
> end -- class MY_TREE

The error message is correct

Regards
Friedrich

--
Please remove just-for-news- to reply via e-mail.
Reply With Quote
  #3  
Old 10-18-2007, 07:34 AM
=?ISO-8859-15?Q?Roman_T=F6ngi?=
Guest
 
Default Re: compilation error

Friedrich Dominicus wrote:
> Roman Töngi <roman.toengi@hispeed.ch> writes:
>
>> I want to traverse a binary search tree and output
>> each node-item.
>> The following does not compile but I have no idea why not.
>> The actual argument "v" has type INTEGER_32.
>> See error message below.
>>
>> class
>> APPLICATION
>> create
>> make
>> feature -- Initialization
>> make is
>> -- Run application.
>> local
>> tree: MY_TREE [INTEGER]
>> do
>> create tree.make (500)
>> tree.put (200)
>> tree.put (100)
>> tree.put (150)
>> tree.put (125)
>> tree.put (600)
>> tree.put (550)
>> tree.put (800)
>> tree.put (700)
>> tree.put (650)
>> tree.put (750)
>> tree.put (725)
>> tree.i_infix
>> end
>> end -- class APPLICATION
>>
>>
>> class
>> MY_TREE [G -> COMPARABLE]
>> inherit
>> BINARY_SEARCH_TREE [G]
>> redefine
>> node_action
>> end
>> create
>> make
>> feature -- Cursor movement
>> node_action (v: like item) is

> this means like G
>> -- Perfom action on item.
>> do
>> io.put_integer (v)

> a G may or may not conform to an integer
>> io.put_character (' ')
>> end
>> invariant
>> invariant_clause: True -- Your invariant here
>> end -- class MY_TREE

> The error message is correct
>
> Regards
> Friedrich
>


Do you have a solution to my problem?
I am a beginner and thankful to any help.

Thx
Reply With Quote
  #4  
Old 10-18-2007, 08:52 AM
J
Guest
 
Default Re: compilation error

As the compiler says the error is on

io.put_integer (v)

in MY_TREE, `v' is of type G (which must conform to COMPARABLE)
However, put_integer accepts only INTEGER values.
What you are trying to do is

io.put_integer (a_comparable_value)

What you might do is

io.put_string (v.out)

For an INTEGER value, v.out will do what you wanted.
But this might not be the case for any object conforming to COMPARABLE.


Hope this helps,
-- Jocelyn.
Reply With Quote
  #5  
Old 10-18-2007, 09:01 AM
Friedrich Dominicus
Guest
 
Default Re: compilation error

sometthing along this lines will work:
indexing
description: "Objects that ..."
author: ""
date: "$Date$"
revision: "$Revision$"

class MY_TREE

inherit BINARY_SEARCH_TREE[INTEGER]
rename
make as bst_make
redefine
node_action
end
creation
make

feature {ANY}
make(v: INTEGER) is
--
do
bst_make(v);
end


feature

node_action(some_int: INTEGER) is
--
do
io.put_integer(some_int);
io.put_character(' ');

end
end


used like this:


class
APPLICATION



create
make

feature -- Initialization

make is
-- Creation procedure.
local
a_tree: MY_TREE;
do
create a_tree.make(100);
a_tree.put(299);
a_tree.put(123);
a_tree.put(1);
a_tree.i_infix;

end


end -- class APPLICATION


Output:

1 100 123 299

Which seems to be ok

Regards
Friedrich


--
Please remove just-for-news- to reply via e-mail.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:33 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.