Instance variable is not initialized. Why is that?

366 views Asked by At

I got this problem with my instance variables. They will not be initialized and I'm unsure what is exactly means. It's the same for every class I have. I posted one of the codes below:

class Good
types
  public evalGood :: 
  good : Good
  price : nat1;

 instance variables
    private owner : Seller;
    private startPrice : nat1;
    private description : seq of char

operations
  public  getStartPrice : ()  ==> nat1
  getStartPrice() == (return startPrice);

end Good

I hope someone can help me and maybe explain why, so it doesn't happen again

Regards, Kamilla

1

There are 1 answers

2
Nick Battle On

When you declare instance variables, their values are "undefined" - ie. no particular value - unless you assign them. You can either do that with an initializer (say ":= 123" on the end) or set them to a value in a constructor. If you do neither, Overture will give you this warning. It is not necessarily an error, but you must set the variables to a value before you use them.