RE: [eiffel-users] Error: variable is not properly set. Attribute(s):name

283 kali dilihat
Langsung ke pesan pertama yang belum dibaca

r...@amalasoft.com

belum dibaca,
21 Mar 2018, 12.24.5821/03/18
kepadaeiffel...@googlegroups.com
The 'name' feature (a STRING attribute) has not been instantiated, and as such violates Void-safety rules.  It must be instantiated (either created or have a non-Void reference attached to it) by the end of the creation sequence of PERSON to be Void-safe.
If you are OK with it being Void some of the time, then mark it as detachable
 
...
name: detachable STRING
...
 
OR, add a form of attachment or instantiation to the creation sequence
 
class PERSON
 
create
    make_with_name
 
feature
    make_with_name (v: like name)
        do
            name := v
        end
...
 
OR perhaps
 
class PERSON
 
inherit
    ANY
        redefine
            default_create
        end 
 
feature
 
    default_create
        do
            create name.make (0)
            Precursor
        end 
...
 
R   
 
-------- Original Message --------
Subject: [eiffel-users] Error: variable is not properly set.
Attribute(s):name
From: Сергей Владимирович <sch...@gmail.com>
Date: Wed, March 21, 2018 9:40 am
To: Eiffel Users <eiffel...@googlegroups.com>

class PERSON

feature

name: STRING

age: INTEGER

end


what am I doing wrong?

Installation information:
Version = EiffelStudio 18.1 (18.01.10.1424 GPL Edition - win64)
$ISE_EIFFEL = D:\eiffel
$ISE_LIBRARY = D:\eiffel
$ISE_PLATFORM = win64
$ISE_C_COMPILER = mingw

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.

Alexander Kogtenkov

belum dibaca,
21 Mar 2018, 16.14.2421/03/18
kepadaeiffel...@googlegroups.com
The error says that the attribute `name` should be set after the object creation, because its type is attached. There are several ways to solve the issue:

1. Mark all reference attributes as detachable:

   class PERSON
        name: detachable STRING
        age: INTEGER
   end

2. Mark the class as deferred, so that no instances of it could be created:

   deferred class PERSON

        name: STRING
        age: INTEGER
   end

3. Add a default creation procedure that initializes the attribute:


   class PERSON inherit ANY redefine default_create end feature
      default_create do name := "" end

      name: STRING
      age: INTEGER
   end

4. Add a creation procedure that will be used to initialize the object:

   class PERSON create make feature
      make (n: like name; y: like age)
         do
            name := n
            age := y
         end

      name: STRING
      age: INTEGER
   end

Hope this helps,
Alexander Kogtenkov

Сергей Владимирович <sch...@gmail.com>:
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru