On Friday, 14 August 2015 at 00:06:33 UTC, Adam D. Ruppe wrote:
On Thursday, 13 August 2015 at 23:48:08 UTC, Jack Stouffer
wrote:
In my code, the list can have 20-30 different types of classes
in it all inheriting from the same interface, and it doesn't
make sense for all of those classes to im
On Thursday, 13 August 2015 at 23:48:08 UTC, Jack Stouffer wrote:
In my code, the list can have 20-30 different types of classes
in it all inheriting from the same interface, and it doesn't
make sense for all of those classes to implement a method that
is very specific to one of the classes.
On 08/13/2015 04:48 PM, Jack Stouffer wrote:
On Thursday, 13 August 2015 at 22:49:15 UTC, Adam D. Ruppe wrote:
On Thursday, 13 August 2015 at 21:42:54 UTC, Jack Stouffer wrote:
dynamically calling different methods on each object in the list
based on its type.
The cleanest OO way of doing tha
On Thursday, 13 August 2015 at 22:49:15 UTC, Adam D. Ruppe wrote:
On Thursday, 13 August 2015 at 21:42:54 UTC, Jack Stouffer
wrote:
dynamically calling different methods on each object in the
list based on its type.
The cleanest OO way of doing that is to put the methods you
need in the inter
On Thursday, 13 August 2015 at 21:42:54 UTC, Jack Stouffer wrote:
dynamically calling different methods on each object in the
list based on its type.
The cleanest OO way of doing that is to put the methods you need
in the interface and always call it through that. Then there's no
need to cast
On Thursday, 13 August 2015 at 22:20:35 UTC, Justin Whear wrote:
foreach (item; parent_list) {
if (auto asA = cast(A)item) {
asA.method();
} else if (auto asB = cast(B)item) {
asB.method2();
}
}
On Thursday, 13 August 2015 at 22:20:35 UTC, Justin Whear wrote:
Thanks Justin and ru
On Thursday, 13 August 2015 at 21:42:54 UTC, Jack Stouffer wrote:
Thanks, that worked, and based on your answer, I was able to
fix my real problem: dynamically calling different methods on
each object in the list based on its type. So, using the above
code as an example, I am able to call meth
On Thu, 13 Aug 2015 21:42:52 +, Jack Stouffer wrote:
> foreach (item; parent_list) {
> string class_name = (cast(Object)
> item).classinfo.name;
> if (class_name == "test.A") {
> (cast(A) item).method();
> } e
On Thursday, 13 August 2015 at 20:28:33 UTC, Adam D. Ruppe wrote:
On Thursday, 13 August 2015 at 20:23:56 UTC, Jack Stouffer
wrote:
As far as I can tell, there is no way to know the actual type
of each of the objects in the list to be able to print:
Cast it to Object first, then do the typeid
On Thursday, 13 August 2015 at 20:23:56 UTC, Jack Stouffer wrote:
As far as I can tell, there is no way to know the actual type
of each of the objects in the list to be able to print:
Cast it to Object first, then do the typeid and it will get the
dynamic class type. Since Parent is an interfa
Given:
interface Parent {
void method();
}
class A : Parent {
void method() {}
this() {}
}
class B : Parent {
void method() {}
void method2() {}
this() {}
}
void main() {
import std.stdio;
Parent[] parent_l
11 matches
Mail list logo