Re: Why structs and classes instanciations are made differently ?

2017-07-26 Thread Ali Çehreli via Digitalmars-d-learn
On 07/26/2017 02:54 AM, Houdini wrote: On Tuesday, 25 July 2017 at 17:16:00 UTC, Kagamin wrote: On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote: Yes, but it isn't the default way in C++ to do dynamic instanciation. https://github.com/isocpp/CppCoreGuidelines this? It's only 2 years

Re: Why structs and classes instanciations are made differently ?

2017-07-26 Thread Patrick Schluter via Digitalmars-d-learn
On Monday, 24 July 2017 at 17:42:30 UTC, Steven Schveighoffer wrote: On 7/24/17 11:45 AM, Houdini wrote: On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer wrote: Because types with inheritance generally don't work right if you pass by value (i.e. the slicing problem). structs

Re: Why structs and classes instanciations are made differently ?

2017-07-26 Thread Houdini via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 17:16:00 UTC, Kagamin wrote: On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote: Yes, but it isn't the default way in C++ to do dynamic instanciation. https://github.com/isocpp/CppCoreGuidelines this? It's only 2 years old. The new operator predates it by

Re: Why structs and classes instanciations are made differently ?

2017-07-25 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote: Yes, but it isn't the default way in C++ to do dynamic instanciation. https://github.com/isocpp/CppCoreGuidelines this? It's only 2 years old. The new operator predates it by decades.

Re: Why structs and classes instanciations are made differently ?

2017-07-25 Thread Houdini via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 15:15:59 UTC, Kagamin wrote: C++ is big, there's always something you don't know about it. Java actually instantiates classes the C++ way: http://en.cppreference.com/w/cpp/language/new Yes, but it isn't the default way in C++ to do dynamic instanciation. Usually,

Re: Why structs and classes instanciations are made differently ?

2017-07-25 Thread Kagamin via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote: D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in Java ? C++ is big, there's always something you don't know about it. Java

Re: Why structs and classes instanciations are made differently ?

2017-07-25 Thread Houdini via Digitalmars-d-learn
On Monday, 24 July 2017 at 17:42:30 UTC, Steven Schveighoffer wrote: In D, I would use classes for any time I need polymorphism, and use structs otherwise. OK, I'll adhere to this method. :) Thanks to all for your answers.

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/17 11:45 AM, Houdini wrote: On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer wrote: Because types with inheritance generally don't work right if you pass by value (i.e. the slicing problem). structs don't support inheritance or virtual functions, so they can be safely

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread via Digitalmars-d-learn
On Mon, Jul 24, 2017 at 03:45:29PM +, Houdini via Digitalmars-d-learn wrote: > But in C++, we pass them by reference also to avoid copies (const &). Exactly... in C++ you basically always pass by reference, so D made that the default.

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Houdini via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer wrote: Because types with inheritance generally don't work right if you pass by value (i.e. the slicing problem). structs don't support inheritance or virtual functions, so they can be safely passed by value. But in C++, we

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Houdini via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:37:51 UTC, Andrea Fontana wrote: Maybe this will help you: https://stackoverflow.com/questions/10965577/usage-preference-between-a-struct-and-a-class-in-d-language Thanks for this informative link.

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/17 11:21 AM, Houdini wrote: Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in Java ? And why is it

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote: Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in

Why structs and classes instanciations are made differently ?

2017-07-24 Thread Houdini via Digitalmars-d-learn
Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in Java ? And why is it different for structs ?