Re: Struct inheritance

2015-02-24 Thread amber via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 12:16:43 UTC, Tobias Pankrath wrote: On Tuesday, 24 February 2015 at 12:05:51 UTC, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? No runtime polymorphism, but a kind of sub typing via alias this. struct S { void

Re: Struct inheritance

2015-02-24 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 12:05:51 UTC, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? No runtime polymorphism, but a kind of sub typing via alias this. struct S { void foo() { writeln(S.foo); } struct T { S s; alias s this; } T t; t.foo();

Struct inheritance

2015-02-24 Thread amber via Digitalmars-d-learn
Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or this(this) {} and what's the difference between these two? Thanks, Amber

Re: Struct inheritance

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or this(this) {} and what's the difference between these two?

Re: Struct inheritance

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 18:19:39 +, ketmar wrote: On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or

Re: Struct inheritance

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or this(this) {} and what's the difference between these two?

Re: Struct inheritance

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 06:22:05PM +, ketmar via Digitalmars-d-learn wrote: On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to

Re: Struct inheritance

2012-02-05 Thread Vidar Wahlberg
Sending this again, got an error the first time and it appears like it was not sent. On 2012-02-04 21:48, Simen Kjærås wrote: I see. There's a hint in the error message: function expected [...], not module. Struct is the name of a module, so the compiler thinks you want to access something

Re: Struct inheritance

2012-02-05 Thread Simen Kjærås
On Sun, 05 Feb 2012 11:58:40 +0100, Vidar Wahlberg cani...@exent.net wrote: Also, is this really ambiguous? Are there any cases where you can have a module name followed by a parentheses, i.e. module(? Not that I know. I cannot seem to recreate this error message. Which version of the

Re: Struct inheritance

2012-02-05 Thread Vidar Wahlberg
On 2012-02-05 14:16, Simen Kjærås wrote: On Sun, 05 Feb 2012 11:58:40 +0100, Vidar Wahlberg cani...@exent.net wrote: Also, is this really ambiguous? Are there any cases where you can have a module name followed by a parentheses, i.e. module(? Not that I know. Possibly something that could

Re: Struct inheritance

2012-02-05 Thread Vidar Wahlberg
On 2012-02-05 15:19, Daniel Murphy wrote: The names only need to match if the compiler/build tool has to find the module itself. If you call the compiler with all modules listed: gdc bar.d Foo.d etc.d then it should be able to work it out. (This is how it works with dmd, anyway. GDC is

Re: Struct inheritance

2012-02-05 Thread Daniel Murphy
I guess you've found a bug then. :) Vidar Wahlberg cani...@exent.net wrote in message news:jgm7sh$k4u$1...@digitalmars.com... On 2012-02-05 15:19, Daniel Murphy wrote: The names only need to match if the compiler/build tool has to find the module itself. If you call the compiler with all

Re: Struct inheritance

2012-02-04 Thread Simen Kjærås
On Sat, 04 Feb 2012 15:04:50 +0100, Vidar Wahlberg cani...@exent.net wrote: This code does not compile: Bar.d:6: Error: function expected before (), not module Struct of type void Bar.d:6: Error: constructor Foo.Foo.this (Struct s) is not callable using argument types (_error_) Why is

Re: Struct inheritance

2012-02-04 Thread Trass3r
So why not just use classes? I've understood it as there may be a performance gain by using structs over classes, and in my program Point and Coordinate are used heavily. The other big difference is value vs. reference type. You can use alias this to achieve something like struct inheritance.

Struct inheritance

2012-02-04 Thread Vidar Wahlberg
Good day. I know inheritance is a misleading word as there's no such thing when it comes to structs, but I couldn't think of a better description for this problem: Let's say I got a struct for a location on a 2-dimensional plane: struct Point { int x; int y; } Further I also need to

Re: Struct inheritance

2012-02-04 Thread Simen Kjærås
On Sat, 04 Feb 2012 12:38:30 +0100, Vidar Wahlberg cani...@exent.net wrote: Good day. I know inheritance is a misleading word as there's no such thing when it comes to structs, but I couldn't think of a better description for this problem: Let's say I got a struct for a location on a

Re: Struct inheritance

2012-02-04 Thread Vidar Wahlberg
On 2012-02-04 13:06, Simen Kjærås wrote: It seems that what you want is alias this: Thank you both, that's exactly what I needed. Leeching a bit more on the thread: Going back to the method: int somethingNifty(Point p) { return p.x + p.y; } Let's say I have the following code: for (x; 0 ..

Re: Struct inheritance

2012-02-04 Thread bearophile
Vidar Wahlberg: Leeching a bit more on the thread: Going back to the method: int somethingNifty(Point p) { return p.x + p.y; } Let's say I have the following code: for (x; 0 .. 10) { for (y; 0 .. 10) { Point p = {x, y}; somethingNifty(p); } } [How] can you

Re: Struct inheritance

2012-02-04 Thread Simen Kjærås
On Sat, 04 Feb 2012 13:55:55 +0100, Vidar Wahlberg cani...@exent.net wrote: On 2012-02-04 13:06, Simen Kjærås wrote: It seems that what you want is alias this: Thank you both, that's exactly what I needed. Leeching a bit more on the thread: Going back to the method: int

Re: Struct inheritance

2012-02-04 Thread Vidar Wahlberg
On 2012-02-04 14:45, Simen Kjærås wrote: Like bearophile said, Point(x, y) should work - assuming you have defined no other constructors for Point. You are correct, my apologies for not testing more thoroughly. Let me try again, explaining the real issue: I have 3 files: -- Bar.d -- import

Re: Struct inheritance

2012-02-04 Thread Ali Çehreli
On 02/04/2012 03:38 AM, Vidar Wahlberg wrote: Let's say I got a struct for a location on a 2-dimensional plane: struct Point { int x; int y; } Further I also need to represent a location in a 3-dimensional space: struct Coordinate { int x; int y; int z; } If these were classes

Re: Struct inheritance

2012-02-04 Thread Ali Çehreli
On 02/04/2012 08:25 AM, Ali Çehreli wrote: The following templatizes the coordinate types, but you could use put write everywhere: That should be ... you could write *ints* everywhere. Ali

Re: struct inheritance need?

2008-12-25 Thread Weed
Kagamin пишет: Weed Wrote: If you do not want to initialize repeatedly matrix inside the sub, which often cause each other, must be static matrices or declared as global (in relation to these procedures). You agree with that? What's problem? If you want static or global variables, you have

Re: struct inheritance need?

2008-12-25 Thread Weed
Kagamin пишет: Weed Wrote: If you do not want to initialize repeatedly matrix inside the sub, which often cause each other, must be static matrices or declared as global (in relation to these procedures). You agree with that? What's problem? If you want static or global variables, you

Re: struct inheritance need?

2008-12-23 Thread Kagamin
Weed Wrote: The problem is not in use templates. Templates are implementing some of the functionality of 2 types of structures matrices (normal and dynamic). But the structures do not inherit, then to add functionality matrix to other entities ( pixel, image etc) sites will have their

Re: struct inheritance need?

2008-12-23 Thread Weed
Kagamin пишет: Weed Wrote: The problem is not in use templates. Templates are implementing some of the functionality of 2 types of structures matrices (normal and dynamic). But the structures do not inherit, then to add functionality matrix to other entities ( pixel, image etc) sites will

Re: struct inheritance need?

2008-12-22 Thread Weed
Kagamin пишет: Weed Wrote: that is, suppose that after some action should get a matrix matrix3x1 Well... if you want to template every piece of your code, this can cause disaster, so I think, this is not very good design. For example, multiplication method will be duplicated N*N*N times for

Re: struct inheritance need?

2008-12-18 Thread Derek Parnell
On Thu, 18 Dec 2008 07:24:34 -0500, Kagamin wrote: Static constructor can execute any valid D statements including construction of objects. A static constructor (also known as the Module constructor) executes at program run-time and not at program compile-time. I think Weed wants the ability

Re: struct inheritance need?

2008-12-17 Thread Kagamin
Weed Wrote: I agree. In my case I chose to structure rather than a class because it can be initialized at compile time. But now I thing must be allowed to deploy class in the default data segment. And add the possibility of creating a object of class at compile time. If you want to

Re: struct inheritance need?

2008-12-17 Thread Janderson
Weed wrote: I should explain why it's important for me: For example, I am making a matrix object(s) It should be: - any size - with ability of making matrix instance of a given size in compile time. - ability of creating matrix instance in runtime. I have decided to make it struct because I

Re: struct inheritance need?

2008-12-16 Thread bearophile
Weed: Planned in the future to implement inheritance of structs or the static creation of classes? Inheritance of structs: I think it's not planned. Structs in D are meant to be used for different things than classes. Yet, as time passes structs are gaining more power: you can't believe that

Re: struct inheritance need?

2008-12-16 Thread Weed
bearophile пишет: Weed: Planned in the future to implement inheritance of structs or the static creation of classes? Inheritance of structs: I think it's not planned. Structs in D are meant to be used for different things than classes. Yet, as time passes structs are gaining more power:

Re: struct inheritance need?

2008-12-16 Thread Weed
Bill Baxter пишет: 2008/12/16 Weed resume...@mail.ru: I should explain why it's important for me: For example, I am making a matrix object(s) It should be: - any size - with ability of making matrix instance of a given size in compile time. - ability of creating matrix instance in runtime. I

Re: struct inheritance need?

2008-12-16 Thread Weed
Bill Baxter пишет: 2008/12/16 Weed resume...@mail.ru: I should explain why it's important for me: For example, I am making a matrix object(s) It should be: - any size - with ability of making matrix instance of a given size in compile time. - ability of creating matrix instance in runtime. I