Re: How to call a extern C++ class constructor ?

2020-02-01 Thread kinke via Digitalmars-d-learn
On Saturday, 1 February 2020 at 14:52:21 UTC, kinke wrote: Trivial cases like yours should actually work wrt. using C++ ctor implementations from D IIRC. Ah, you need at least one virtual function in the C++ class (because D always reserves a vptr, the pointer to the class vtable).

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread kinke via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:15:20 UTC, Luhrel wrote: But somehow I got a segfault on dcpp.getNumber(true). That's because you declare it as virtual in D (default for classes, use `final`), but non-virtual in C++. You also forgot to add the class field to the D declaration (yes, D

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 1 February 2020 at 10:21:54 UTC, norm wrote: On Saturday, 1 February 2020 at 08:38:22 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:32:51 UTC, Ferhat Kurtulmuş wrote: On Saturday, 1 February 2020 at 08:27:07 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:21:29 UTC,

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread norm via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:38:22 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:32:51 UTC, Ferhat Kurtulmuş wrote: On Saturday, 1 February 2020 at 08:27:07 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş wrote: You cannot.

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Luhrel via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:32:51 UTC, Ferhat Kurtulmuş wrote: On Saturday, 1 February 2020 at 08:27:07 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş wrote: You cannot. https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d You must

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:27:07 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş wrote: You cannot. https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d You must use a factory method like createInstance. Oh I see, so there's

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Luhrel via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş wrote: You cannot. https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d You must use a factory method like createInstance. Oh I see, so there's definitively no way to call a c++ ctor without modifying the c++

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:15:20 UTC, Luhrel wrote: Hello there, I would like to know how can I call a C++ ctor. [...] You cannot. https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d You must use a factory method like createInstance.

How to call a extern C++ class constructor ?

2020-02-01 Thread Luhrel via Digitalmars-d-learn
Hello there, I would like to know how can I call a C++ ctor. Actually, I have this: C++: CppClass.cpp #include "CppClass.h" AmazingCppClass::AmazingCppClass() { number = 124; } int AmazingCppClass::getNumber(bool show) { if (show)