On 11/3/22 1:46 PM, Tejas wrote:
Check my post, `A& a;` refuses to compile in C++20 atleast, asking to be
explicitly initialized, thus averting the problem altogether
That's different, `A&` cannot be rebound in C++, whereas a class
reference can.
Try `A* a;` and see if it compiles
-Steve
On Thursday, 3 November 2022 at 15:40:02 UTC, H. S. Teoh wrote:
On Thu, Nov 03, 2022 at 04:41:14AM +, Siarhei Siamashka via
Digitalmars-d-learn wrote: [...]
```D
@safe:
import std.stdio;
class A {
void foo() { writeln("foo"); }
}
void main() {
auto a1 = new A;
a1.foo(); // prints
On 11/3/22 08:40, H. S. Teoh wrote:
> D does not have the equivalent of C++'s allocating a class instance on
> the stack.
Not by default but we have two different ways, either may be discouraged:
import std.typecons : scoped;
import std.stdio;
class C {
int i;
}
void main() {
//
On Thursday, 3 November 2022 at 15:40:02 UTC, H. S. Teoh wrote:
D does not have the equivalent of C++'s allocating a class
instance on the stack. In D, all class instances are allocated
on the heap and class variables are references to them.
well there is
scope Object o = new Object;
which
On Thu, Nov 03, 2022 at 04:41:14AM +, Siarhei Siamashka via
Digitalmars-d-learn wrote:
[...]
> ```D
> @safe:
> import std.stdio;
> class A {
> void foo() { writeln("foo"); }
> }
> void main() {
> auto a1 = new A;
> a1.foo(); // prints "foo"
> A a2;
> a2.foo(); // Segmentation fault
On Thursday, 3 November 2022 at 04:41:14 UTC, Siarhei Siamashka
wrote:
C++ code:
```C++
#include
class A {
public:
void foo() { std::cout << "foo" << std::endl; }
};
int main() {
auto a1 = new A;
a1->foo(); // prints "foo"
A a2;
a2.foo(); // prints "foo"
delete a1;
}
```
D code:
On Thursday, 3 November 2022 at 06:02:13 UTC, Mike Parker wrote:
are in C++. D enforces the distinction that C++
...that C++ programmers often follow by convention.
On Thursday, 3 November 2022 at 05:41:06 UTC, Siarhei Siamashka
wrote:
Thanks for the link and also thanks for confirming that you
have no clue what's going on. I think that what actually
That's not necessary. He does know what's going on and pointed
you to the correct place. The second
On Thursday, 3 November 2022 at 05:10:06 UTC, matheus wrote:
https://dlang.org/spec/class.html
Thanks for the link and also thanks for confirming that you have
no clue what's going on. I think that what actually happens is
that the D code
```D
A a2;
a2.foo();
```
is roughly equivalent
On Thursday, 3 November 2022 at 04:41:14 UTC, Siarhei Siamashka
wrote:
...
https://dlang.org/spec/class.html
Matheus.
10 matches
Mail list logo