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.
2,276
questions
0
votes
1
answer
79
views
Why is C++ implicitly converting 0.0 to some extremly small 'random' value? [duplicate]
I'm trying to compare two class objects, which has both been initialized with 0.0, but for some reason C++ decides to convert the 0.0 to some extremly small value instead of keeping the 0.0, which ...
0
votes
0
answers
28
views
MVVM - Convert 2 viewmodels into a view
I am working on a module where I am using MVVM. I have one model Patient.cs and 3 view models ViewModel1, ViewModel2, ViewModel3. I'm having hard time converting 3 view models into one model. Can ...
9
votes
1
answer
164
views
in C++, can template function taking class object instantiate object with it's constructors arguments?
let's say i have a template function taking a class object:
template<class T>
void Foo(T obj);
and a class definition as follows:
class Bar
{
public:
Bar(int a, bool b): _a(a), _b(b) {}
...
0
votes
0
answers
53
views
C++ Implicit conversion of a class to std::string [duplicate]
Below is a partial class SafeString (omitting not related methods):
class SafeString
{
private:
char* _str = nullptr;
public:
operator std::string() const {
return { _str };
}
...
0
votes
1
answer
36
views
TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256[3] memory to uint256[] memory requested
so I got a problem while developing a contract using a foundry. So I have a function that takes uint256 with array type as an argument. But when I did the test, It showed an implicit error.
TypeError: ...
2
votes
2
answers
56
views
Implicit conversion to string does not work with `==` operator [duplicate]
Given the following code compiled with g++-7 7.4.0 c++17:
#include <iostream>
#include <string>
using namespace std;
struct A
{
int value = 3;
operator int()
{
return ...
-1
votes
3
answers
78
views
How to access a[m][n] 2D array using double pointer? [duplicate]
How to access a[m][n] 2D array using double pointer?
I dont't no why **b can't be used to access 2D array value?
I want to do it without changing "int **b = num;"
----------------------------...
1
vote
1
answer
73
views
What's Difference Between p and p[x] (Pointers in C)
#include <stdio.h>
int main(){
int a[] = {1,2,3};
int *p = &a;
}
p = adress of a variable.
*p = The value in that adress.
I understand this but why p is memory adress but p[x] isn't?
For ...
2
votes
2
answers
57
views
C# explanation of the "f" keyword for a float vs implicit and explicit conversions
So I don't really get the conversion from a float to a double e.g:
float wow = 1.123562641346;
float wow = 1.123562641346f;
The first one is a double that gets saved in a variable that has memory ...
0
votes
2
answers
49
views
lvalue required as left operand of assignment - What causes this error and how to fix it?
Here is the piece of code. Its in C, compiler is CodeBlocks
I made a function Replacethings which is supposed to replace all characters that are spaces, commas, and exclamation points with *. ...
-3
votes
2
answers
57
views
== doesn't works when comparing argv[] strings [duplicate]
I noticed that comparing a normal string variable with a string using strcmp and == operator both works, but comparing argv string using == doesn't works, only it works with strcmp. why? What is so ...
6
votes
1
answer
114
views
Is there any difference between overflow and implicit conversion, whether technical or bit level (cpu-register-level)?
(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 ...
0
votes
0
answers
38
views
c++ - does std::is_convertible checks if temporary is created?
I've been examining this paper on the origins of std::forward, and the author (in exemplifying the last, 5th implementation of the one) wrote the following:
It allows any conversion in which a ...
0
votes
2
answers
38
views
warning: incompatible pointer types [-Wincompatible-pointer-types] in C
Why do I get a warning here? How can I fix this?
memUnit * newUnit = (char*) freeUnit + sizeof(memUnit);
I want to allocate a new Unit after the old Unit in my Memory (basically DIY calloc()). All ...
0
votes
2
answers
77
views
How do Array Pointers behave?
I was trying to write the code for storing multiplication table in array.
First I wrote the following code.
#include<stdio.h>
void Multiplication(int arr[][10], int num,int size);
int main(){
...
3
votes
1
answer
69
views
MSVC won't perform a user-defined implicit conversion to std::nullptr_t when invoking operator==
Consider the following piece of code:
struct X { operator std::nullptr_t() const { return nullptr; } };
X x;
assert(x == nullptr);
As far as I can tell, it should work because X is implicitly ...
1
vote
2
answers
64
views
Pointer to constant array
I am making a multi-language interface for an AVR system, the strings are stored in the program memory with each language string placed in its own array. The idea is that when the user switches ...
1
vote
3
answers
121
views
What is " int (**p)[2]; "?
Here is the problem:
#include <stdio.h>
int main()
{
int a[2][2] = { {6, 2}, {3, 4} };
int (**p)[2];
p = a;
for (int i = 0; i < 4; i++) {
printf("%p\n&...
3
votes
5
answers
148
views
Why is char** argv same as char* argv[]
So I have read that behind the scenes when passing an array in a function the compiler turns
int myArray(int arr[])
into
int myArray(int *arr)
Also an array most of the times decays to a pointer, ...
0
votes
2
answers
43
views
Taking address of fixed-size-array argument seemingly fails. Why?
I am playing with example code provided in one of the answers to
typedef fixed length array .
The answer only states that the code fails, but does not explain, why. Could anyone provide an explanation?...
0
votes
2
answers
42
views
Implicit conversion of Int* to custom class in function call
I have a custom type MySeq extending IndexedSeq[Int] and its implicit conversion:
package example
import scala.language.implicitConversions
class MySeq(vals: IndexedSeq[Int]) extends IndexedSeq[Int] ...
0
votes
0
answers
90
views
What does mean by "S1 is a proper subsequence of S2"
[over.ics.rank]#3.2:
Standard conversion sequence S1 is a better conversion sequence than
standard conversion sequence S2 if,
(3.2.1) S1 is a proper subsequence of S2 (comparing the conversion ...
0
votes
1
answer
25
views
Strict Properties Without Option Strict On
When Option Strict is turned Off, which is the default for my application, VB will automatically convert the value when property is String. It appears to call the toString() of the incoming value's ...
0
votes
0
answers
51
views
Confustion about bullet [over.ics.rank]/(3.2.1) [duplicate]
My problem lies in un-understanding the following paragraph from the standard, and I can't figure out in which case this rule is applied.
over.ics.rank#3.2.1:
S1 is a proper subsequence of S2 (...
2
votes
1
answer
34
views
I need help understanding the proper usage of "pointer to array of n integers" initialization [duplicate]
The following declaration:
int (*x)[10]
is defined as x is an integer pointer to an integer array of 10 elements.
Question 1 : Doesn't this mean that x initially points to the first element of an ...
0
votes
1
answer
35
views
dereferencing 2D array using arithmetic
int main(void)
{
short arr[3][2]={3,5,11,14,17,20};
printf("%d %d",*(arr+1)[1],**(arr+2));
return 0;
}
Hi. In above code as per my understanding ,*(arr+1)[1] is equivalent to *...
0
votes
0
answers
47
views
How to compare conversion sequences that have multiple contained conversion sequences? [duplicate]
I get confused when I tried to understand this question: How to compare two standard conversion sequences use the rank of contained conversions.
I used to see only that a conversion sequence has only ...
2
votes
4
answers
90
views
Using a pointer to point to a certain row in c
If I have array a, how would I set a pointer to the first row?
double a[2][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
0
votes
0
answers
44
views
Scala: Cannot prove that Node <:< IdHolder[Int]
I'm working on a project with both java and scala modules. I have a generic method that causes the error Cannot prove that Node <:< IdHolder[Int]:
def fetchElement[T](url: String)(implicit ev: T ...
-1
votes
2
answers
60
views
Why char* directly set the value but not in the case of int* in c programming
There is no existence of string as a primitive data type in c
language. char* make string exist. If a list of character set to an
pointer like this (char *msg = "HI!") but why not in the ...
2
votes
0
answers
40
views
SQL Impala convert NaN values to NULL values
I have the following column in my table:
col 1
1
3
NULL
NaN
5
"Bad" aggregations return NaN instead of NULL and the variable is type DOUBLE in the end.
I want to have one type of ...
0
votes
1
answer
59
views
Fixed-size array as function parameter: No matching function for call to 'begin' [duplicate]
I am passing a fixed size array to a function (the size is defined to a constant in the function's definition). However, I still get the error
No matching function for call to 'begin'
# define ...
1
vote
3
answers
58
views
Array changes it's values inside a function but other variable don't [duplicate]
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void func(int arr[5], int n1, int n2)
{
cout << "INSIDE func()" << endl;
arr[0]++, arr[3]+...
1
vote
0
answers
41
views
Recursive generics with one-to-many external reference, dynamic types
I have a database structure (which unfortunately I cannot modify) according to the attached scheme. In practice I have an entity (TBL-A) which has a parent-child hierarchical structure and has an ...
-1
votes
1
answer
39
views
defining a generic implicit conversion to nullable [duplicate]
I have the following struct:
struct Generic<T>
{
public T Property { get; init; }
public Generic(T property) { Property = property; }
public static implicit operator T?(Generic<T&...
4
votes
2
answers
71
views
Why can an array used in fread/fwrite in a position of a buffer be written with or without & and yield the same result?
Why do these yield the same result?
uint8_t header[HEADER_SIZE];
fread(&header, sizeof(uint8_t), HEADER_SIZE, input);
fwrite(&header, sizeof(uint8_t), HEADER_SIZE, output);
uint8_t header[...
0
votes
2
answers
43
views
Inserting values to 2D array using pointers
I successfully entered values to a 2D array without pointers
int main(){
int A[2][3];
for (int i=0; i<2; i++){
for(int j=0; j<3; j++){
A[i][j] = 2*i+3*j;
...
-1
votes
1
answer
61
views
c#: define an implicit conversion on a property {get; set} for class
I would like to create a class type that seems to be a double value but adds some functionality to it.
I know the possibility described here. But this does not allow to assign a value to an existing ...
2
votes
1
answer
56
views
std::array<int> iterator convertible to int* on clang but not MSVC?
So I have some code like
void func( const int* begin, const int* end );
and then want to use std::array<int, X> to have the data stored, and then call the function like so:
std::array<int, 5&...
1
vote
1
answer
94
views
AND Operation for -1
While implementing logical operations in the code, I discovered a phenomenon where it should not be entered in the if statement.
It turns out that this is the AND (&&) operation of -1 and ...
2
votes
2
answers
69
views
How to return a 2D array?
I was searching for an efficient way to create a 2D array and return it, usually I make an array of pointers, allocate memory for each pointer, and return an **ptr. I was looking for another way to do ...
-1
votes
1
answer
59
views
Why and when to use pointers in C? [closed]
I'm still very new to C, have only been learning for about a week at this point, but something I don't get is the use of pointers. I get how pointers work and I know how to use them, but I don't see ...
0
votes
1
answer
70
views
"C" Trying to understand **pointer and how to access all values of value[][]
#include "stdio.h"
int main()
{
int *pI, *values[2];
int i1[] = {1, 2}, i2[][2] = {{5, 10}, {20, 30}};
// SOME LINES ARE EDITED, AFTER READING COMMENTS
*values = i2[*i1]; ...
1
vote
1
answer
44
views
Calling constructor with string argument passing char * report error
template<typename T>
class SharedValue {
public:
SharedValue(const T& t): valuePtr(new T(t)) {}
const SharedValue& operator = (const T &t) {
*valuePtr = t;
...
1
vote
3
answers
68
views
What's the difference between defining 2d array: int *arr[ ] and int arr[ ][ ] in terms of how they're represented in memory?
I've been trying to understand the difference between the two definitions and how to use them properly.
it seems to me that defining a 2d array with arr[length][width] stores the content of the matrix ...
1
vote
1
answer
45
views
what happens here: typedef int (*ptr) (void) in .h file C
I have a piece of C code and don't understand what happens here:
typedef int (*ptr) (void *ptr2, const char *name);
What I do understand is the typedef int (*ptr) part, but what happens in the second(...
0
votes
0
answers
24
views
Why is there a seemingly random conversion of floats to ints with aggregation functions
From the python pandas pivot table reference the difference between the fourth last and third last example is simply to add this parameter: 'fill_value=0'.
Yet the difference to the table is much ...
1
vote
1
answer
73
views
Basic pointer question about allocating the address
The following is my program
#include<stdio.h>
int main(){
int a[][4] = {1, 2, 3, 4, 5, 6, 7, 8};
int (*ptr)[4] = a;
for (int i=0; i< 4; i++){
printf("\n Address ...
1
vote
1
answer
109
views
How to stop c++ implicitly converting double to bool?
I have a struct that is a json library that has these as their constructors:
JSONValue(std::string input);
JSONValue(double input);
JSONValue(bool input);
JSONValue(std::map<std::string, JSONValue&...
-1
votes
2
answers
44
views
MSVC - expression must have pointer-to-object type but it has type "float" on generic array?
MSVC on Visual Studio 2019 says "expression must have pointer-to-object type but it has type "float" on generic array" here:
void _stdcall sample::Eff_Render(PWAV32FS SourceBuffer, ...