What's wrong??? I can't create an object...

3 Messages Forum Options Options
Permalink
LordThomas
What's wrong??? I can't create an object...
Reply Threaded More
Print post
Permalink
I'am new in Eiffel language and i cant understand what changes i must do in order to run successfully???
This is my class:

class PERSON
                creation
                        make
                feature
                        age: INTEGER;
            sex: CHARACTER;
          name: STRING;
              address: STRING;

                        change_address(new_address:STRING) is
            do
                                address := new_address;
            end -- change_address
                        inc_age   is
                do
                    age := age +1;
                end -- inc_age
                        display is
                  do
                                io.put_string(name);
  if sex = 'm' or sex = 'M'
                                        then io.put_string("Male")
                                elseif sex ='f' or sex = 'F'
                                        then io.put_string("Female");
                                end -- if
                                io.put_integer(age);
                                io.put_new_line;
                        io.put_string(address);
                                io.put_new_line;
      end -- display
                        make(p_name:STRING;m_or_f:CHARACTER;
                                     p_age:INTEGER)      is
                do
                                name := p_name;
                                age := p_age;  
                  sex := m_or_f;
                end -- make
  end -- PERSON

and i create 3 objects in this class:

class CONTROLLER    
                creation
                test
                feature
                    p1, p2, p3 : PERSON;

      test is
            do
                          !!p1.make("Jim Perera",'M',31);
                            !!p2.make("Anne Jones",'F',27);
                            !!p3.make("Robert Bruce",'M',56);  
                                               
              end -- test
                                end -- CONTROLLER


During compilation it shows me an error in class PERSON.
bloombladder
Re: What's wrong??? I can't create an object...
Reply Threaded More
Print post
Permalink
Hi there!
The problem i think you have, is the following: When you create a new Project the default setting for the creation procedure in the root class, which i guess you renamed to "CONTROLLER", has the name "make" and you named it  "test". This obviously leads to an inconsitency.
What to do: you have three possibilities to solve this Problem:
1. Rename your creation procedure to "make" instead of "test".
2. Go to Project -> Project settings; click on "target: person"; and in the "general" section click in the line root on  the "CONTROLLER.make" (if I got your problem right, it should have that name). This should open a little window where you can edit the root. Rename the "root procedure" to "test" instead of "make.
3. go to the folder where you saved the project, open the ecf-file, and in the line <root class="CONTROLLER" feature="make"/> change the "make" to "test".

I hope i understood your problem right, and this post solves it. If not, then please post the exact error-message you get when you try to compile. btw. next time please try to be more precise about your problem and format your code a little bit more readable.

LordThomas wrote:
I'am new in Eiffel language and i cant understand what changes i must do in order to run successfully???
This is my class:

class PERSON
                creation
                        make
                feature
                        age: INTEGER;
            sex: CHARACTER;
          name: STRING;
              address: STRING;

                        change_address(new_address:STRING) is
            do
                                address := new_address;
            end -- change_address
                        inc_age   is
                do
                    age := age +1;
                end -- inc_age
                        display is
                  do
                                io.put_string(name);
  if sex = 'm' or sex = 'M'
                                        then io.put_string("Male")
                                elseif sex ='f' or sex = 'F'
                                        then io.put_string("Female");
                                end -- if
                                io.put_integer(age);
                                io.put_new_line;
                        io.put_string(address);
                                io.put_new_line;
      end -- display
                        make(p_name:STRING;m_or_f:CHARACTER;
                                     p_age:INTEGER)      is
                do
                                name := p_name;
                                age := p_age;  
                  sex := m_or_f;
                end -- make
  end -- PERSON

and i create 3 objects in this class:

class CONTROLLER    
                creation
                test
                feature
                    p1, p2, p3 : PERSON;

      test is
            do
                          !!p1.make("Jim Perera",'M',31);
                            !!p2.make("Anne Jones",'F',27);
                            !!p3.make("Robert Bruce",'M',56);  
                                               
              end -- test
                                end -- CONTROLLER


During compilation it shows me an error in class PERSON.
LordThomas
Re: What's wrong??? I can't create an object...
Reply Threaded More
Print post
Permalink
The second suggestion solved my problem.Thank you very much!!!
May i ask you one more thing? Why in the class CONTROLLER where i create 3 objects when i want to print them, it prints only the first one. I use the display function (e.g. for the object p1 i write p1.display) from the PERSON class.why does this happen?

bloombladder wrote:
Hi there!
The problem i think you have, is the following: When you create a new Project the default setting for the creation procedure in the root class, which i guess you renamed to "CONTROLLER", has the name "make" and you named it  "test". This obviously leads to an inconsitency.
What to do: you have three possibilities to solve this Problem:
1. Rename your creation procedure to "make" instead of "test".
2. Go to Project -> Project settings; click on "target: person"; and in the "general" section click in the line root on  the "CONTROLLER.make" (if I got your problem right, it should have that name). This should open a little window where you can edit the root. Rename the "root procedure" to "test" instead of "make.
3. go to the folder where you saved the project, open the ecf-file, and in the line <root class="CONTROLLER" feature="make"/> change the "make" to "test".

I hope i understood your problem right, and this post solves it. If not, then please post the exact error-message you get when you try to compile. btw. next time please try to be more precise about your problem and format your code a little bit more readable.