What changes to C++ made copy initialization work for class with explicit constructor?

Because the behavior of copy elision changes from C++17; for this case copy elision is mandatory. Mandatory elision of copy/move operations Under the following circumstances, the compilers are required to omit the copy and move construction of class objects, even if the copy/move constructor and the destructor have observable side-effects. The objects are constructed directly … Read more

Why does the compiler choose bool over string for implicit typecast of L””?

First, the cause of this issue: C++ Standard [over.ics.rank]/2.11 defines an order for conversion sequences. It says that a user defined conversion sequence is worse than a standard conversion sequence. What happens in your case is that the string literal undergoes a boolean-conversion (defined at 4.12. This is a standard conversion). It does not use … Read more

Explicit copy constructor

The explicit copy constructor means that the copy constructor will not be called implicitly, which is what happens in the expression: CustomString s = CustomString(“test”); This expression literally means: create a temporary CustomString using the constructor that takes a const char*. Implicitly call the copy constructor of CustomString to copy from that temporary into s. … Read more

Can a cast operator be explicit?

Yes and No. It depends on which version of C++, you’re using. C++98 and C++03 do not support explicit type conversion operators But C++11 does. Example, struct A { //implicit conversion to int operator int() { return 100; } //explicit conversion to std::string explicit operator std::string() { return “explicit”; } }; int main() { A … Read more

Incorrectly aligned or overlapped by a non-object field error

The CF Marshaler isn’t so good at this type of thing and what you’re attempting is unsupported. The problem is that it knows that the first element is unaligned, but it seems to not understand that each element in the array would also be unaligned. You can see the behavior works in this example: [StructLayout(LayoutKind.Explicit, … Read more