compiler-generated

Can a trivial type class be copied when not all its members are initialized?

笑着哭i 提交于 2020-03-18 09:42:31
问题 (I just realized I first need to solve a much more basic issue with copying unions: When a union object is copied, is a member subobject created?. Please see that other question first.) The implicitly generated copy operations (constructor and assignment) of a class perform member by member copy (initialization or assignment). (For a trivial type these are the same.) So a class with some members not initialized cannot be copied, as accessing uninitialized objects is illegal. struct C { int m1

Are any C++ operator overloads provided automatically based on others?

淺唱寂寞╮ 提交于 2019-12-10 17:44:27
问题 Say I'm writing an int wrapper and need to provide every single operator overload. Must the author list out every single one, or can it auto-generate any based on what the author has provided? Can/does the compiler infer any new auto-defined operators from existing ones? If I define operator== , does it give me an operator!= automatically? Or vice-versa? If I define operator++() , do I get operator++(int) for free? Or vice versa? How about the += type business? Can it combine existing

Implicit conversion to System.Double with a nullable struct via compiler generated locals: why is this failing?

只愿长相守 提交于 2019-12-03 03:10:13
问题 Given the following, why does the InvalidCastException get thrown? I can't see why it should be outside of a bug (this is in x86; x64 crashes with a 0xC0000005 in clrjit.dll). class Program { static void Main(string[] args) { MyDouble? my = new MyDouble(1.0); Boolean compare = my == 0.0; } struct MyDouble { Double? _value; public MyDouble(Double value) { _value = value; } public static implicit operator Double(MyDouble value) { if (value._value.HasValue) { return value._value.Value; } throw

Implicit conversion to System.Double with a nullable struct via compiler generated locals: why is this failing?

余生长醉 提交于 2019-12-02 16:39:59
Given the following, why does the InvalidCastException get thrown? I can't see why it should be outside of a bug (this is in x86; x64 crashes with a 0xC0000005 in clrjit.dll). class Program { static void Main(string[] args) { MyDouble? my = new MyDouble(1.0); Boolean compare = my == 0.0; } struct MyDouble { Double? _value; public MyDouble(Double value) { _value = value; } public static implicit operator Double(MyDouble value) { if (value._value.HasValue) { return value._value.Value; } throw new InvalidCastException("MyDouble value cannot convert to System.Double: no value present."); } } }

Will the compiler-generated default constructor be public?

为君一笑 提交于 2019-12-01 04:26:23
When I write a class Widget.java public class Widget { int data; String name; } will the compiler-generated constructor be public or default ? public would be like public class Widget { int data; String name; public Widget() {} } whereas default similar to public class Widget { int data; String name; Widget() {} } It depends on your class visibility .The compiler uses the class visibility and generates a no-arg default constructor with the same visibility As said in JLS If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically

Will the compiler-generated default constructor be public?

隐身守侯 提交于 2019-12-01 01:54:26
问题 When I write a class Widget.java public class Widget { int data; String name; } will the compiler-generated constructor be public or default ? public would be like public class Widget { int data; String name; public Widget() {} } whereas default similar to public class Widget { int data; String name; Widget() {} } 回答1: It depends on your class visibility .The compiler uses the class visibility and generates a no-arg default constructor with the same visibility 回答2: As said in JLS If a class