Re: Use class template as a type

2016-11-29 Thread ag0aep6g via Digitalmars-d-learn
On 11/29/2016 02:21 AM, Basile B. wrote: The cast from a class type to a sub class in itself does absolutely nothing. That can't be right. A bad downcast gives you null, so it has to check the dynamic type information. Compare with upcasts which are statically known to be correct, so they don

How can I concatenate a string, a char array and an int

2016-11-29 Thread Anders S via Digitalmars-d-learn
Hi guys, just started to get into Dlang, comming from C and C++ I like to use methods like there if possible. Now I want to catenate something like this, but don't get it to work in standard C i code: char str[80]; sprintf(str, "This is a number = %f", 3.14356); Now in Dlang and impor

Re: How can I concatenate a string, a char array and an int

2016-11-29 Thread rumbu via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 10:21:24 UTC, Anders S wrote: Hi guys, just started to get into Dlang, comming from C and C++ I like to use methods like there if possible. Now I want to catenate something like this, but don't get it to work in standard C i code: char str[80]; sprintf(

how to copy const struct with indirections to mutable one (of the same type)

2016-11-29 Thread drug via Digitalmars-d-learn
I had the following code: ``` import std.algorithm: equal; struct Data { int[3] arr; } int main() { auto const_data = const(Data)([1, 2, 3]); assert(const_data.arr[].equal([1, 2, 3])); Data mutable_data = const_data; assert(mutable_data.ar

Re: how to copy const struct with indirections to mutable one (of the same type)

2016-11-29 Thread Mathias Lang via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 10:46:04 UTC, drug wrote: I had the following code: ``` import std.algorithm: equal; [...] You are not calling the (identity) opAssign here, but postblit. To call identity opAssign, you need an already constructed instance: ``` Data mutable_data; mutable_dat

Re: how to copy const struct with indirections to mutable one (of the same type)

2016-11-29 Thread drug via Digitalmars-d-learn
29.11.2016 13:49, Mathias Lang пишет: On Tuesday, 29 November 2016 at 10:46:04 UTC, drug wrote: I had the following code: ``` import std.algorithm: equal; [...] You are not calling the (identity) opAssign here, but postblit. To call identity opAssign, you need an already constructed instance

Re: How can I concatenate a string, a char array and an int

2016-11-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 10:21:24 UTC, Anders S wrote: Hi guys, just started to get into Dlang, comming from C and C++ I like to use methods like there if possible. Now I want to catenate something like this, but don't get it to work in standard C i code: char str[80]; sprintf(

Re: Converting all enum members to a string fails with version 2.0.72.0

2016-11-29 Thread Stefan via Digitalmars-d-learn
On Monday, 21 November 2016 at 18:53:59 UTC, Stefan wrote: On Monday, 21 November 2016 at 17:26:37 UTC, Jonathan M Davis wrote: [...] Thanks Jonathan for the explanation. The cast works fine but feels "unsafe". I will wait for the next version. Stefan Version D 2.072.1 Beta fixed my prob

Re: How can I concatenate a string, a char array and an int

2016-11-29 Thread Anders S via Digitalmars-d-learn
Thanks guys for a really quick answer !! OK, a little bit awkward to use but getting there posting a new question about char * to struct ;) Thanks /anders

Cannot implicitly convert expression (&sbuf) of type char [1024] to IOREQ *

2016-11-29 Thread Anders S via Digitalmars-d-learn
Hi guys, I want to write into a fifo pipe using write( ...) Now a gather my data into my own struct IOREQ so in order to write I have to cast into an char buffer. My problem in dlang is that it doesn't accept the casting (IOREQ *) I get: Error: Cannot implicitly convert expression (&sbuf) of

Re: Cannot implicitly convert expression (&sbuf) of type char [1024] to IOREQ *

2016-11-29 Thread Nemanja Boric via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 15:55:57 UTC, Nemanja Boric wrote: just struct IOREQ { SHORT fc; /* function code */ SHORT rs; /* return code */ INT size; /* size of this request, including */ SHOR

Re: Cannot implicitly convert expression (&sbuf) of type char [1024] to IOREQ *

2016-11-29 Thread Nemanja Boric via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 15:30:33 UTC, Anders S wrote: Hi guys, I want to write into a fifo pipe using write( ...) Now a gather my data into my own struct IOREQ so in order to write I have to cast into an char buffer. My problem in dlang is that it doesn't accept the casting (IOREQ *)

Re: Use class template as a type

2016-11-29 Thread Jerry via Digitalmars-d-learn
On Monday, 28 November 2016 at 11:26:41 UTC, dm wrote: ``` abstract class MyClass(T) { public: @property const(T) value(){return _value;} @property void value(T val){_value = val;} ... private: T _value; ... } To avoid having to use the Object class directly you can make an base c

Re: Use class template as a type

2016-11-29 Thread Jerry via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 15:56:23 UTC, Jerry wrote: abstract class MyClass {} abstract class MyClassImpl(T) Oops, forgot MyClassImpl should extend from MyClass. abstract class MyClassImpl(T) : MyClass { ... }

Re: Cannot implicitly convert expression (&sbuf) of type char [1024] to IOREQ *

2016-11-29 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/2016 07:30 AM, Anders S wrote: > INTargv[1];/* list of arguments */ In addition to what Nemanja Boric wrote, the recommended array syntax in D is the following: INT[1] argv; > char sbuf[1024]; > io = (IOREQ *)buf; // Not accepted in dlang You must use t

Re: Cannot implicitly convert expression (&sbuf) of type char [1024] to IOREQ *

2016-11-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 23:33:19 UTC, Ali Çehreli wrote: On 11/29/2016 07:30 AM, Anders S wrote: > INTargv[1];/* list of arguments */ Speculation, but given that you say "list of args" is it possible OP means to use int[0] for an inline array. In addition to what Ne

Re: Cannot implicitly convert expression (&sbuf) of type char [1024] to IOREQ *

2016-11-29 Thread Anders S via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 23:33:19 UTC, Ali Çehreli wrote: On 11/29/2016 07:30 AM, Anders S wrote: > INTargv[1];/* list of arguments */ In addition to what Nemanja Boric wrote, the recommended array syntax in D is the following: INT[1] argv; > char sbuf[1024]; >