Questions tagged [implicit-conversion]
Converting an object, variable or value from one type to another to satisfy a type restriction, without specifically requesting that conversion through language syntax.
implicit-conversion
2,460
questions
2
votes
3
answers
100
views
Converting to char*** from char* [2][2]
I have the following variable
char* a[2][2] = {{"123", "456"}, {"234", "567"}};
I wanted to refer it using another variable. While the cast works, accessing ...
0
votes
2
answers
61
views
Is the & operator is essential to use as address operator [duplicate]
#include<stdio.h>
int main()
{
int a[5]={5,10,15,20,25};
int *p;
int i;
p=a;
for (i=0;i<=5;i++)
{
printf("the address of the %d is = %d\n",*p,p);
...
0
votes
0
answers
56
views
More than one operator “=” error while compiling with CUDA 12.2 [closed]
I am trying to build Spconv library with CUDA 12.2 and GCC 9 (for some reasons I can't use GCC version > 10)
There is a problem related to implicit conversions:
[build] /usr/include/c++/9/bits/...
1
vote
1
answer
63
views
Implicit function parameter conversion not happening [duplicate]
I have the following piece of code:
template<class A>
struct X {
template<class T>
X(T t) {}
};
template<class A>
void f(X<A> x, A a) {}
int main() {
...
1
vote
1
answer
73
views
How to trigger implicit pointer conversion inline in a C macro?
Context
I have some functions to support using a custom memory allocator in my library:
void *(allocate)(struct allocator *allocator, size_t size, size_t alignment);
void (deallocate)(struct allocator ...
0
votes
1
answer
40
views
Why a stack overflow from my Scala implicit conversion?
I have an issue with my code where I'm getting a stack overflow exception when doing an implicit conversion from Calendar to PublicationSchedule. I've cut down the code and can reproduce in Scastie (...
0
votes
0
answers
36
views
Implicit conversion of subtypes not recognized by Scala 3 compiler
I have the following code:
enum Value {
case Nil
case Boolean(value: scala.Boolean)
case Number(value: Double)
case String(value: String)
}
object Value {
given Conversion[scala.Boolean, ...
8
votes
1
answer
71
views
Which compiler is correct for this reference initialization with user-defined conversions?
Consider:
struct A {};
struct B {
operator A&() volatile;
operator A&() const;
operator A&&();
};
B b;
const A& a = b;
(godbolt link: https://godbolt.org/z/jcYch9jdW)...
2
votes
1
answer
43
views
Do implicit and explicit transformations in C# affect real type transformations?
Why in the reference type, even if implicit conversion is done, the actual type conversion is not done even if explicit conversion is done?
While studying explicit and implicit transformations, I was ...
2
votes
3
answers
114
views
How can I prevent implicit conversion with C++ function arguments when using concepts?
I'm trying to use C++20 concepts to enforce an interface on multiple classes (and I do not want to use pure virtual functions). The problem I'm running into seems to be that implicit conversions ...
0
votes
2
answers
58
views
Converting generic types implicitly
I have a generic Result class
I want to write an implicit operator function so I can cast Result-T to Result-V but I could not figure out how to do it.
public class Result<T>
{
public bool ...
-4
votes
2
answers
116
views
Why do the two pointer arrays return different addresses?
In the following code, I thought that the two outputs were the same. But in fact they are not! In my computer, the first output is 0x6ffde0, while the latter output is 0x6ffdb0.
#include<iostream&...
1
vote
2
answers
93
views
Implicit conversion between a Union Type and Either in Scala 3
I'm trying to develop an implicit converter from type Error | A to type Either[Error, A] in Scala 3. The code of the converter is the following:
object MyConversions:
given unionTypeToEither[Error, ...
0
votes
0
answers
71
views
Why is the compiler chosing a different constructor in implicit conversion? [duplicate]
I'm writing a program to better understand implicit and explicit conversion in c++ and I've came up with this simple code:
#include <iostream>
#include <format>
class Entity
{
public:
...
3
votes
2
answers
74
views
Implicit conversion from non-const to const pair template parameter and invocation of copy/move ctors on unoredered_map::insert in C++
Code
#include <iostream>
#include <unordered_map>
#include <utility>
using namespace std;
struct Foo {
Foo(const int value) : val(value) {
cout << "Foo(int), ...