implicit-conversion Questions

1

Solved

(I'm an novice, so there may be inaccuracies in what I say) In my current mental model, an overflow is an arithmetical phenomenon (occurs when we perform arithmetic operations), and an implicit con...

5

Solved

Given Type a and Type b, how can I, at runtime, determine whether there's an implicit conversion from a to b? If that doesn't make sense, consider the following method: public PropertyInfo GetCom...
Muire asked 8/2, 2010 at 19:30

4

Solved

It seems the GCC and Clang interpret addition between a signed and unsigned integers differently, depending on their size. Why is this, and is the conversion consistent on all compilers and platfor...
Vilmavim asked 29/4, 2022 at 13:43

5

Solved

Consider this piece of code: struct Base { int x; }; struct Bar : Base { int y; }; struct Foo : Base { int z; }; Bar* bar = new Bar; Foo* foo = new Foo; Base* returnBase() { Base* obj = !b...
Robertoroberts asked 12/3, 2018 at 16:22

15

Solved

Is it possible to define an implicit conversion of enums in c#? something that could achieve this? public enum MyEnum { one = 1, two = 2 } MyEnum number = MyEnum.one; long i = number; If not,...
Roane asked 4/11, 2008 at 12:6

5

Solved

Regular static allocated array looks like this, and may be accessed using the following formulas: const int N = 3; const int M = 3; int a1[N][M] = { {0,1,2}, {3,4,5}, {6,7,8} }; int x = a1[1][2];...

2

class X{ public: X(){} }; class Y{ public: Y(X x) { std::cout << "Temporary created!"; } }; int main(){ X x; const Y& y = x; return 0; } Why does temporary object (of ty...
Reber asked 4/4, 2022 at 15:45

1

Solved

I am learning smart pointers, with the following example test.cpp #include<iostream> #include<vector> #include<memory> struct abstractShape { virtual void Print() const=0; }; s...
Steffie asked 2/4, 2022 at 9:36

1

Solved

Why does an implicit conversion to [byte] work, but when replacing byte by bool it no longer works? I. e. the following works... Add-Type -TypeDefinition @' public readonly struct MyByte { private...

1

Solved

template<typename Integral> struct IntegralWrapper { Integral _value; IntegralWrapper() = default; IntegralWrapper(Integral value) : _value(value) {} operator Integral() const { ret...

2

I used to always copy and paste my code in cppinsights to see where's in my code a conversation is performed implicitly by the compiler. But pointer-to-member standard conversion is not shown on th...
Topsyturvydom asked 21/3, 2022 at 19:5

2

Solved

I'm working on a Windows Forms application, and it contains custom controls with methods that can potentially be called from threads other than the UI thread. So these methods therefore look a bit ...
Razorback asked 17/7, 2015 at 10:34

1

Solved

TL;DR: I am looking for a C++14 equivalent of the following C++20 MWE: template<int sz> struct bits { int v; // note explicit(expr) below explicit(sz > 1) operator bool() const { return ...

5

Solved

I recently found this code: public static implicit operator XElement(XmlBase xmlBase) { return xmlBase.Xml; } What does static implicit operator mean?
Goodson asked 25/11, 2010 at 4:32

2

Solved

I am trying to understand overloading resolution in C++ through the books listed here. One such example that i wrote to clear my concepts whose output i am unable to understand is given below. #in...

1

Solved

In the following code struct A has two implicit conversion operators to char and int, and an instance of the struct is compared for equality against integer constant 2: struct A { constexpr operat...

1

Solved

Rationale for C, Revision 5.10, April-2003: It is invalid to convert a pointer to a function of one type to a pointer to a function of a different type without a cast. It seems that they wanted t...
Blueweed asked 10/1, 2022 at 14:28

8

Solved

Why does the first and second Write work but not the last? Is there a way I can allow all 3 of them and detect if it was 1, (int)1 or i passed in? And really why is one allowed but the last? The se...
Sirmons asked 11/7, 2012 at 12:18

2

Solved

What is the difference between functions, which have reference to an array: // reference to array void f_(char (&t)[5]) { auto t2 = t; } and simply array: // just array void f__(char t[5]) { ...
Galitea asked 17/12, 2021 at 18:4

1

Based on the answer in Implicit conversion when overloading operators for template classes I was able to write the following code that works perfectly fine (simplified example): namespace my_librar...
Mestee asked 4/12, 2021 at 23:28

1

Solved

Consider the following code (https://godbolt.org/z/s17aoczj6): template<class T> class Wrapper { public: explicit Wrapper(T t): _value(t) {} template<class S = T> operator T() { re...
Undersecretary asked 30/11, 2021 at 10:45

1

I'm trying to rid my codebase of lossy implicit conversions, so I'm compiling with the -Wconversion flag under clang++. The following code is expected to output a warning, but does not. #include &...
Leonoreleonsis asked 11/4, 2019 at 19:40

1

I am trying to write a simple class that will act as a complex<double> number when used in a context that warrants a complex number, otherwise it will act as a double (with the requirement th...
Careycarfare asked 14/10, 2020 at 2:54

4

Solved

For example, I have the following code: let numberOfBlocks = 3 let blockWidth = SKSpriteNode(imageNamed: "image.png").size.width let padding = 20.0 let offsetX : Float = (self.frame.size.widt...
Savage asked 9/7, 2014 at 5:11

3

Solved

I have case class with joda Datetime field: case DomainPositionData(domain: String, position: Int, change: Option[Int], date:DateTime) Trying to use macro to generate reader&writer: implici...
Heaviness asked 21/5, 2013 at 6:53

© 2022 - 2024 — McMap. All rights reserved.