Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/20 10:11 AM, Steven Schveighoffer wrote b.step(); // virtual call, calls B.step I meant, calls A.step; -Steve

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/20 8:05 AM, Mihail Lorenko wrote: On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote: On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote:     B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Mihail Lorenko via Digitalmars-d-learn
On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote: On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work. Thanks for

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work.

Re: Object oriented programming and interfaces

2017-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/4/17 3:43 PM, Dirk wrote: Hi! I defined an interface: interface Medoid {     float distance( Medoid other );     uint id() const @property; } and a class implementing that interface: class Item : Medoid {     float distance( Item i ) {...}     uint id() const @property {...} } The

Re: Object oriented programming and interfaces

2017-12-05 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! I defined an interface: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @pr

Re: Object oriented programming and interfaces

2017-12-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 07:47:32 UTC, Dirk wrote: The distance function is implementation dependend and can only be computed between two objects of the same class (in this example the class is Item). Just don't put it in the interface. Leave it in the individual classes with the strict

Re: Object oriented programming and interfaces

2017-12-05 Thread bauss via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 08:08:55 UTC, Daniel Kozak wrote: You can do something like this: interface Medoid(T) { float distance( T other ); uint id() const @property; } class Item : Medoid!(Item) { float distance( Item m ) { return 0.;} uint id() const @property { return 1

Re: Object oriented programming and interfaces

2017-12-05 Thread Daniel Kozak via Digitalmars-d-learn
You can do something like this: interface Medoid(T) { float distance( T other ); uint id() const @property; } class Item : Medoid!(Item) { float distance( Item m ) { return 0.;} uint id() const @property { return 1; } } class MedoidClassification { this(T:Medoid!T)(T[] list)

Re: Object oriented programming and interfaces

2017-12-05 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 07:47:32 UTC, Dirk wrote: What would be a good way to implement this? Did you tried to use introspection?

Re: Object oriented programming and interfaces

2017-12-04 Thread Dirk via Digitalmars-d-learn
The distance function is implementation dependend and can only be computed between two objects of the same class (in this example the class is Item). My goal is to write a module for a k-medoids clustering algorithm. The class MedoidClassification shall be able to partition a list of objects

Re: Object oriented programming and interfaces

2017-12-04 Thread A Guy With a Question via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! float distance( Medoid other ); float distance( Item i ) {...} The two signatures need to be the same. I think this is true of most OOP languages. Have them both be: float distance( Medoid other );

Re: Object oriented programming and interfaces

2017-12-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-12-04 21:43, Dirk wrote: Hi! I defined an interface: interface Medoid {     float distance( Medoid other );     uint id() const @property; } and a class implementing that interface: class Item : Medoid {     float distance( Item i ) {...}     uint id() const @property {...} } The

Re: Object oriented programming and interfaces

2017-12-04 Thread Craig Dillabaugh via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! I defined an interface: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @pr

Re: Object oriented programming and interfaces

2017-12-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @property {...} } The compiler s

Re: Object as function argument

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 19:51:09 UTC, Max Klyga wrote: If you really need the actual pointer to object data you can use `*cast(void**)&myObject`. Compiler cannot cast object reference to `void*` but we can trick it ;) It can, actually. A class can define its own cast(void*) though, so th

Re: Object as function argument

2015-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:08:08 UTC, Chris Sperandio wrote: Is it clean to write this code below ? yup. Though remember all the downsides of null - if you try to use a null object like accessing a member, the program will be terminated.

Re: Object as function argument

2015-03-05 Thread Chris Sperandio via Digitalmars-d-learn
Ok... So, in D when I work with Object, it's like if I work with only pointers. Thus, I can return null from a function which returns an Item instance. Is it clean to write this code below ? static Item nullReturn(Item item) { // ... // and for some cases return null; }

Re: Object as function argument

2015-03-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 05, 2015 19:35:34 Chris Sperandio via Digitalmars-d-learn wrote: > Hi, > > I'm a developer coming from C and I've a question about class > instance as method or function parameter. > In the book "The D Programming Language", I read the instance was > passed by reference to funct

Re: Object as function argument

2015-03-05 Thread Chris Sperandio via Digitalmars-d-learn
Below the code: module item; import std.stdio; class Item { ulong count; static void call1(Item item) { writeln("(call1) Addr: ", &item); } static void call2(ref Item item) { writeln("(call2) Addr: ", &item); } static Item call3(Item item) { writeln("(call3) Add

Re: Object as function argument

2015-03-05 Thread Max Klyga via Digitalmars-d-learn
On 2015-03-05 19:35:34 +, Chris Sperandio said: Hi, I'm a developer coming from C and I've a question about class instance as method or function parameter. In the book "The D Programming Language", I read the instance was passed by reference to functions (in the opposite of structures). I

Re: Object as function argument

2015-03-05 Thread w0rp via Digitalmars-d-learn
On Thursday, 5 March 2015 at 19:35:35 UTC, Chris Sperandio wrote: Hi, I'm a developer coming from C and I've a question about class instance as method or function parameter. In the book "The D Programming Language", I read the instance was passed by reference to functions (in the opposite of

Re: object hijacked ?

2014-10-09 Thread Jacob Carlborg via Digitalmars-d-learn
On 09/10/14 22:06, Dicebot wrote: I think this is an issue with the import resolution, not module system. The way it is implemented right now DMD stops searching for object.d / object.di once it has found one. So while your module name is not interpreted as "object" _original_ object.di does not

Re: object hijacked ?

2014-10-09 Thread Dicebot via Digitalmars-d-learn
I think this is an issue with the import resolution, not module system. The way it is implemented right now DMD stops searching for object.d / object.di once it has found one. So while your module name is not interpreted as "object" _original_ object.di does not get imported and you get lot of

Re: Object destruction versus finalization

2013-11-14 Thread Florian
Michael, thank you for these links. Regards, Florian.

Re: Object destruction versus finalization

2013-11-13 Thread Michael
Additional discussions http://forum.dlang.org/thread/jpl93e$1mns$1...@digitalmars.com and http://forum.dlang.org/thread/l3dj7b$2tvc$1...@digitalmars.com

Re: Object destruction versus finalization

2013-11-13 Thread Florian
Jonathan, Dicebot, thank you very much for your response. So you are confirming my conclusion, that finalizers/destructors in D work pretty much like in C++ and there is no way to do Java/C#/Managed C++-like finalization. For the records, since Dicebot asked: I am using DMD32 v2.063.2 on De

Re: Object destruction versus finalization

2013-11-12 Thread Dicebot
On Tuesday, 12 November 2013 at 22:40:26 UTC, Florian wrote: The example below prints the following output: ~Connection ~Session segmentation fault Same example prints this for me (no segfault): ~Session shutdown ~Connection 2.064.2 @ linux-64 What is your system / compiler? Outp

Re: Object destruction versus finalization

2013-11-12 Thread Dicebot
On Tuesday, 12 November 2013 at 23:18:11 UTC, Jonathan M Davis wrote: You can't do that in finalizer, because the GC can choose to free it before the finalizer even runs (this avoids issues with circular references). Ah, damn, have forgotten about it. Disregard previous post.

Re: Object destruction versus finalization

2013-11-12 Thread Jonathan M Davis
On Wednesday, November 13, 2013 00:07:12 Florian wrote: > I understood very well, that the garbage collector is not > guaranteed to run. However, it does not explain the segmentation > fault in my example, does it? You're getting a segfault, because you're using something which is on the GC heap

Re: Object destruction versus finalization

2013-11-12 Thread Florian
I understood very well, that the garbage collector is not guaranteed to run. However, it does not explain the segmentation fault in my example, does it?

Re: Object destruction versus finalization

2013-11-12 Thread Jonathan M Davis
On Tuesday, November 12, 2013 23:40:24 Florian wrote: > it would be possible to move the shutdown() sequence into the > destructor of the "Connection" class. Classes in D do not have destructors. Only structs to. ~this is a destructor in a struct, but it's a finalizer in a class. Finalizers are n

Re: Object destruction versus finalization

2013-11-12 Thread Florian
On Tuesday, 12 November 2013 at 20:29:13 UTC, Dicebot wrote: On Tuesday, 12 November 2013 at 20:15:02 UTC, Florian wrote: I played around a little and figured out, that destructors in D work quite similarily to destructors in C++. They are invoked, after the members of the instance being destru

Re: Object destruction versus finalization

2013-11-12 Thread Dicebot
On Tuesday, 12 November 2013 at 20:15:02 UTC, Florian wrote: I played around a little and figured out, that destructors in D work quite similarily to destructors in C++. They are invoked, after the members of the instance being destructed have been destroyed themselfes (or at least have been br

Re: Object construction and this

2013-11-10 Thread Alexandr Druzhinin
10.11.2013 23:22, Benjamin Thaut пишет: Am 10.11.2013 17:06, schrieb Alexandr Druzhinin: Because in D Classes are reference types. That means the code you wrote is equivalent to the following C++ source: class Foo { public: Foo(Object* o) { printf("%x\n", &this); // print a Foo**

Re: Object construction and this

2013-11-10 Thread Benjamin Thaut
Am 10.11.2013 17:06, schrieb Alexandr Druzhinin: Could somebody explain why this http://dpaste.dzfl.pl/248262b9 return this: Foo: 7FBFD59A50 7FBFD59A80 Bar: 7FBFD59A58 7FBFD59A88 Why this value in ctor is different from this value out of ctor if ctor gets an argument? Because in D Classes are r

Re: Object construction and this

2013-11-10 Thread anonymous
On Sunday, 10 November 2013 at 16:06:40 UTC, Alexandr Druzhinin wrote: Could somebody explain why this http://dpaste.dzfl.pl/248262b9 return this: Foo: 7FBFD59A50 7FBFD59A80 Bar: 7FBFD59A58 7FBFD59A88 Why this value in ctor is different from this value out of ctor if ctor gets an argument? Th

Re: Object Pointer

2012-07-18 Thread Jonathan M Davis
On Wednesday, July 18, 2012 20:37:50 Namespace wrote: > Only for correctness: > If i allocate memory on the GC Heap in e.g. a struct and don't > free the memory in the DTor, then the GC free the memory > automatically? You don't normally _ever_ free memory from the GC heap. That's the GC's job. T

Re: Object Pointer

2012-07-18 Thread Namespace
Only for correctness: If i allocate memory on the GC Heap in e.g. a struct and don't free the memory in the DTor, then the GC free the memory automatically?

Re: Object Pointer

2012-07-16 Thread Jonathan M Davis
On Monday, July 16, 2012 10:31:11 Namespace wrote: > I'm just experiement with D, that's all. ;) > Most of my questions here are just out of curiosity. > > I have now this construct: > > [code] > class smart_ptr { > private: > A* _ptr; > > public: > this(A* ptr) { > voi

Re: Object Pointer

2012-07-16 Thread Namespace
I'm just experiement with D, that's all. ;) Most of my questions here are just out of curiosity. I have now this construct: [code] class smart_ptr { private: A* _ptr; public: this(A* ptr) { void* buffer = GC.malloc(A.sizeof); memcpy(buffer, ptr, A

Re: Object Pointer

2012-07-16 Thread Jonathan M Davis
On Monday, July 16, 2012 09:33:42 Namespace wrote: > Yes. I want a Pointer of Foo's reference, you're right. I think i > have to move the reference to the heap? If you don't want it to point to a local variable and cause problems when it goes out of scope, then yeah, though I don't know if it's p

Re: Object Pointer

2012-07-16 Thread Namespace
You cannot have pointers to classes. The language does not support it. You can have pointers to class references, and you can have pointers to structs or the built-in types, but if Foo is a class, then what you can't have a pointer to it. The closest that you can get is that I believe that you c

Re: Object Pointer

2012-07-15 Thread Jonathan M Davis
On Monday, July 16, 2012 00:47:27 Namespace wrote: > Is something like this possible? > > Foo* create_ptr(Foo f) { > assert(f !is null); > // ... > } > > Foo* fp = create_ptr(new Foo()); > > with "ref Foo f" of course, there is no limitation. You cannot have pointers to classes. The l

Re: Object Cast

2012-06-22 Thread Namespace
Seems to me that you achieved the your first purpose. Do you need more help? Kenji Hara I think i'm finished. Or have you any tip for me, related to the code?

Re: Object Cast

2012-06-21 Thread Kenji Hara
On Thursday, 21 June 2012 at 21:32:57 UTC, Namespace wrote: Works in dmd 2.059 too. Oh, good. [code] T template_cast(T : Object, U : Object)(U value) { // try to convert T val = cast(T) value; // if convert was successful, return if (val !is null) {

Re: Object Cast

2012-06-21 Thread Namespace
Works in dmd 2.059 too. [code] T template_cast(T : Object, U : Object)(U value) { // try to convert T val = cast(T) value; // if convert was successful, return if (val !is null) { return val; } // if cast fails it

Re: Object Cast

2012-06-21 Thread Kenji Hara
On Thursday, 21 June 2012 at 10:33:41 UTC, Namespace wrote: To solve the problem of converting a Object to a specific template class i wrote this little function. But the mixin disturbs me. How i can get the type (in this example Vector2D) without to mix a mixin and T.stringof? [code] T object

Re: Object Serialization?

2012-04-27 Thread Dejan Lekic
dcoder wrote: > Hello. > > I'm probably not looking hard enough, but Do we have any > standard d-library for serializing an object/object tree into > -for example- an xml file? > > thanks. You have following - Orange - Thrift implementation - BSON (http://vibed.org) Probably wrappers or bi

Re: Object Serialization?

2012-04-26 Thread Jordi Sayol
Al 24/04/12 18:45, En/na David Nadlinger ha escrit: > On Tuesday, 24 April 2012 at 16:42:19 UTC, dcoder wrote: >> I'm probably not looking hard enough, but Do we have any standard >> d-library for serializing an object/object tree into -for example- an xml >> file? > > There is no standard l

Re: Object Serialization?

2012-04-25 Thread Jacob Carlborg
On 2012-04-24 23:30, sclytrack wrote: Does it automatically pick everything to serialize? Yes. How would you make it more selective? It depends on what you want to do. struct Me { int x; int y; } serialize x but not y. In this simple case you can do like this: struct Me { int x;

Re: Object Serialization?

2012-04-24 Thread sclytrack
On 04/24/2012 08:50 PM, Jacob Carlborg wrote: On 2012-04-24 18:42, dcoder wrote: Hello. I'm probably not looking hard enough, but Do we have any standard d-library for serializing an object/object tree into -for example- an xml file? thanks. You can have a look at Orange: https://github

Re: Object Serialization?

2012-04-24 Thread Jacob Carlborg
On 2012-04-24 18:42, dcoder wrote: Hello. I'm probably not looking hard enough, but Do we have any standard d-library for serializing an object/object tree into -for example- an xml file? thanks. You can have a look at Orange: https://github.com/jacob-carlborg/orange Tutorials: http://

Re: Object Serialization?

2012-04-24 Thread David Nadlinger
On Tuesday, 24 April 2012 at 16:42:19 UTC, dcoder wrote: I'm probably not looking hard enough, but Do we have any standard d-library for serializing an object/object tree into -for example- an xml file? There is no standard library support yet, but you might want to look at Orange (full f

Re: Object

2011-06-13 Thread Lloyd Dupont
I see mm Thanks for the info! "Jonathan M Davis" wrote in message news:mailman.866.1307943671.14074.digitalmars-d-le...@puremagic.com... Object is not currently const-correct: http://d.puremagic.com/issues/show_bug.cgi?id=1824 As a result, a number of basic functions do not currently

Re: Object

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 22:37, Jonathan M Davis wrote: > On 2011-06-12 22:25, Lloyd Dupont wrote: > > I have problem with "Object" > > > > for example this doesn't compile: > > === > > Object o; > > o = ""; > > === > > with error: cannot implicitly convert expression ("") of type string to > > object.Object

Re: Object

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 22:25, Lloyd Dupont wrote: > I have problem with "Object" > > for example this doesn't compile: > === > Object o; > o = ""; > === > with error: cannot implicitly convert expression ("") of type string to > object.Object Object is the base class of all classes. Nothing which is not a

Re: Object di (Newbie)

2010-10-07 Thread Steven Schveighoffer
On Thu, 07 Oct 2010 07:50:49 -0400, Vasileios Anagnostopoulos wrote: What is the purpose of object.di? where can I learn more? http://www.digitalmars.com/d/2.0/dmd-linux.html#interface_files I believe the purpose for object.di is to hide the runtime implementation from the importer.

Re: Object removing own last reference.

2010-06-25 Thread strtr
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article > strtr wrote: > > > > void externalFunc(){} > > > > class C > > { > > .. > > int index_; > > int yay; > > void removeMe() > > { > > //remove last reference to this object > > objects[_index] = null; > > > > //ot

Re: Object removing own last reference.

2010-06-25 Thread Simen kjaeraas
strtr wrote: void externalFunc(){} class C { .. int index_; int yay; void removeMe() { //remove last reference to this object objects[_index] = null; //other critical code memberFunc(); externalFunc(); } void memberFunc(){yay++} } Is there anything unsafe a

Re: Object removing own last reference.

2010-06-24 Thread marksibly
Hi, Shouldn't be as 'this' will keep the object alive as long as necessary. Mark

Re: object splitting in multiple threads

2009-01-10 Thread Jarrett Billingsley
On Sat, Jan 10, 2009 at 6:39 AM, downs wrote: > Jarrett Billingsley wrote: >> On Sat, Jan 10, 2009 at 12:30 AM, Jarrett Billingsley >> wrote: >>> On Sat, Jan 10, 2009 at 12:18 AM, yes wrote: Does Phobos also do threadpools? >>> From what I understand, not without modification. At least, no

Re: object splitting in multiple threads

2009-01-10 Thread downs
Jarrett Billingsley wrote: > On Sat, Jan 10, 2009 at 12:30 AM, Jarrett Billingsley > wrote: >> On Sat, Jan 10, 2009 at 12:18 AM, yes wrote: >>> Does Phobos also do threadpools? >> From what I understand, not without modification. At least, not >> efficiently. Downs has implemented such a thing

Re: object splitting in multiple threads

2009-01-09 Thread Jarrett Billingsley
On Sat, Jan 10, 2009 at 12:18 AM, yes wrote: > Does Phobos also do threadpools? >From what I understand, not without modification. At least, not efficiently. Downs has implemented such a thing in scrapple.tools, but it requires a patch to Phobos to make it run at a reasonable speed. > Somehow

Re: object splitting in multiple threads

2009-01-09 Thread Jarrett Billingsley
On Sat, Jan 10, 2009 at 12:30 AM, Jarrett Billingsley wrote: > On Sat, Jan 10, 2009 at 12:18 AM, yes wrote: >> Does Phobos also do threadpools? > > From what I understand, not without modification. At least, not > efficiently. Downs has implemented such a thing in scrapple.tools, > but it requi

Re: object splitting in multiple threads

2009-01-09 Thread yes
Does Phobos also do threadpools? Somehow I liked the idea of an Object like agent smith, just duplicate yourself when the task is too big. ( ^_^ ) > > > Hm... I guess I understand now, you need a task parallelization, right? > > In order to do this, you usually separate the task into several

Re: object splitting in multiple threads

2009-01-09 Thread Denis Koroskin
On Sat, 10 Jan 2009 07:32:43 +0300, yes wrote: What does this code do? It looks like a ThreadPool use case but I might be wrong. I tried to recursively make an object distribute its calculations. The calculations should take at least a minute. Hm... I guess I understand now, you need

Re: object splitting in multiple threads

2009-01-09 Thread yes
> > What does this code do? It looks like a ThreadPool use case but I might be > wrong. > I tried to recursively make an object distribute its calculations. The calculations should take at least a minute.

Re: object splitting in multiple threads

2009-01-09 Thread Denis Koroskin
On Sat, 10 Jan 2009 05:44:20 +0300, yes wrote: How bad is the following idea? class Calc { void addThread() { Data data; data = new Data(); } void run() { if ( hardware threads > current threadcount) { addThread(); } //wait for some signal //run calculations on data / threads } } Cal