www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I call super or object.opAssign for classes?

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
class Foo
{
    void opAssign(int bar)
    {
    }
}

void main()
{
    auto foo = new Foo;
    foo = null;
}

test.d(17): Error: function test.Foo.opAssign (int bar) is not
callable using argument types (void*)
test.d(17): Error: cannot implicitly convert expression (null) of type
void* to int

I just wanted to implement one opAssign method for assigning a
specific type, but now I've ran into the issue that assigning class
objects to null doesn't work anymore.. :/
Jul 23 2011
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Sat, 23 Jul 2011 12:23:07 -0400, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 class Foo
 {
     void opAssign(int bar)
     {
     }
 }

 void main()
 {
     auto foo = new Foo;
     foo = null;
 }

 test.d(17): Error: function test.Foo.opAssign (int bar) is not
 callable using argument types (void*)
 test.d(17): Error: cannot implicitly convert expression (null) of type
 void* to int

 I just wanted to implement one opAssign method for assigning a
 specific type, but now I've ran into the issue that assigning class
 objects to null doesn't work anymore.. :/

That's a bug, please file. -Steve
Jul 25 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6378

On 7/25/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:
 On Sat, 23 Jul 2011 12:23:07 -0400, Andrej Mitrovic
 <andrej.mitrovich gmail.com> wrote:

 class Foo
 {
     void opAssign(int bar)
     {
     }
 }

 void main()
 {
     auto foo = new Foo;
     foo = null;
 }

 test.d(17): Error: function test.Foo.opAssign (int bar) is not
 callable using argument types (void*)
 test.d(17): Error: cannot implicitly convert expression (null) of type
 void* to int

 I just wanted to implement one opAssign method for assigning a
 specific type, but now I've ran into the issue that assigning class
 objects to null doesn't work anymore.. :/

That's a bug, please file. -Steve

Jul 25 2011
prev sibling next sibling parent =?ISO-8859-1?Q?Diego_Canuh=E9?= <canuhedc gmail.com> writes:
--20cf307c9d9a9f648a04a8f79951
Content-Type: text/plain; charset=ISO-8859-1

Hi,
isn't that the way it's supposed to work? I mean

void show(int a) { writeln(a); }

void main() { show(null); }

won't compile either.
Shouldn't bar be some kind of pointer?

btw, today I read "opAssign can no longer be overloaded for class objects"
here:

http://www.d-programming-language.org/features2.html

is that no longer valid?

--20cf307c9d9a9f648a04a8f79951
Content-Type: text/html; charset=ISO-8859-1

Hi,<br>isn&#39;t that the way it&#39;s supposed to work? I mean<br><br>void
show(int a) { writeln(a); }<br><br>void main() { show(null); }<br><br>won&#39;t
compile either.<br>Shouldn&#39;t bar be some kind of pointer?<br><br>
btw, today I read &quot;opAssign can no longer be overloaded for class
objects&quot; here:<br><br><a
href="http://www.d-programming-language.org/features2.html">http://www.d-programming-language.org/features2.html</a><br>
<br>is that no longer valid?<br>

--20cf307c9d9a9f648a04a8f79951--
Jul 26 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 26 Jul 2011 07:54:54 -0400, Diego Canuh=C3=A9 <canuhedc gmail.co=
m>  =

wrote:

 Hi,
 isn't that the way it's supposed to work? I mean

 void show(int a) { writeln(a); }

 void main() { show(null); }

 won't compile either.
 Shouldn't bar be some kind of pointer?

null should be considered as the type of the class, not void *. You = should not be able to override the behavior of opAssign as it pertains t= o = assigning to a class instance. In other words, you should *never* be ab= le = to override x =3D null where x is a class instance.
 btw, today I read "opAssign can no longer be overloaded for class  =

 objects"
 here:

 http://www.d-programming-language.org/features2.html

 is that no longer valid?

Here is the spec. I would not trust that features2, it's probably out o= f = date. http://www.d-programming-language.org/operatoroverloading.html#Assignmen= t -Steve
Jul 26 2011