www.digitalmars.com         C & C++   DMDScript  

D - Implicit conversion of properties

reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
Shouldn't it be possible to use properties
as the type they represent without casting?

I had a property foo of type float which
I tried to return in some other function.

float bar()
{
    return foo;
}

For this to work I must cast foo to float:

return (float)foo;

Lars Ivar Igesund
Sep 23 2003
next sibling parent "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
More problems:

In the subclass to where the property foo is
declared; I'm not allowed to do any of these:

super.foo = value; // foo and value are floats
this.foo = value;
foo = value;

There first returns this error:
'super.foo()' is not an lvalue

The other to this:
'this.foo()' is not an lvalue

(Shouldn't it be 'a lvalue', not 'an lvalue'?)

Lars Ivar Igesund
Sep 23 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:bkp1pc$2gmn$1 digitaldaemon.com...
 Shouldn't it be possible to use properties
 as the type they represent without casting?

 I had a property foo of type float which
 I tried to return in some other function.

 float bar()
 {
     return foo;
 }

 For this to work I must cast foo to float:

 return (float)foo;

Can you make a complete source snipped illustrating this? How is foo defined?
Sep 23 2003
parent "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bkr2gi$29sc$2 digitaldaemon.com...
 Can you make a complete source snipped illustrating this? How is foo
 defined?

This don't compile with 0.73 until return foo; is changed to return (float)foo; in the subclass. The set method works without casting. In my other post I said that setting like this don't work, but that only seems to be the case when i qualify foo with this or super. class bar { public: float foo() { return bar; } float foo(float value) { return bar = value; } private: float bar; } class subbar : bar { public: float subfoo() { return foo; } float subfoo(float value) { return foo = value; } } Lars Ivar Igesund
Sep 24 2003