2,499 questions
0
votes
0
answers
110
views
Why does initialization of vector of class with implicit string constructor from string literal fail?
The following code fails to compile.
#include <iostream>
#include <map>
#include <vector>
using namespace std;
class mc
{
string s;
public:
mc(const std::string s) : s{...
0
votes
1
answer
1k
views
Implicit conversion operator with generic type
I am trying to write generic method, which should parse JToken to concrete type, by using implicit conversion operator.
I've got my implicit operator like this:
public static implicit operator ...
1
vote
2
answers
94
views
initialization from incompatible pointer type when assigning a pointer to a 2d array
int main()
{
char artist1[4][80] = {};
char artist2[4][80] = {};
char (*pb1)[4][80] = artist1;
char (*pb2)[4][80] = artist2;
char *arrptr[2] = {pb1, pb2};
}
I am trying to ...
0
votes
1
answer
72
views
C# Implicit conversion confusion with generics
Why do I get this error from my code?
OtaqGetAllRq cannot be used as type parameter ... There is no implicit reference conversion from OtaqGetAllRq to CrudGetAllRequestBase<BaseAxtarishVM>
...
1
vote
2
answers
158
views
2D array manipulation with pointers
I am trying to manipulate some 2D array using pointers, I know the basics of pointers but I am having difficulties with this code :
{
char a[3][10] = { "Malek", "Zied",&...
1
vote
1
answer
74
views
How to define a implicit (given) Conversion for Generic Types?
I want to use the Scala 3 Implicit Conversion.
I have the following construct that I want to migrate:
implicit def toTesterObjectScenario[In <: Product](
...
-1
votes
3
answers
942
views
Accessing the bool data type in printf in the C language [closed]
What if I want to print a bool var value, but I used %f and %s in the printf format string? How does the code work?
bool a = true;
bool b = "true";
bool c = '\0';
bool d = "\0";
...
1
vote
1
answer
49
views
diffrent results when trying to find length of an array using pointer arithmetic inside a function and inside of main
for some odd reason when I run this code:
int func(int arr[],int n) {
int a = *(&arr + 1) - arr;
printf("%d",a);
}
I get an address,
and when I run the same code inside main I ...
4
votes
1
answer
232
views
Supposedly ambiguous explicit conversion operator in MSVC, not in gcc or clang
Consider the following class that implements a user-conversion to std::string and const char*:
class String {
public:
String(std::string_view s) : str{s} {}
operator std::string() const {
...
-1
votes
2
answers
99
views
How to define a pointer to an array of class pointers of Size MAX in C++
I have an array of size MAX of class pointers.
How can I define a pointer to the same, and access member functions of base, derived, etc?
class base
{
public :
base() {cout << "base ...
0
votes
2
answers
66
views
Unexpected output found while dealing with a pointer to an array
when i tried to understand more about how array name is treated as pointer, I wrote this code :
#include<stdio.h>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6};
printf("%d \n",*...
0
votes
1
answer
268
views
How to write an implicit Numeric for a tuple
I have a scenario where I would like to call sum on a sequence of (Double, Double) tuples.
Ideally I would like to do something like the following:
implicit def toTupleNumeric[T](num: Numeric[T]) = ...
1
vote
1
answer
303
views
Multiple explicit constructors and implicit conversion
I have a class like this:
class Foo
{
private:
std::string m_data;
public:
Foo() = default;
explicit Foo(double value);
explicit Foo(float value);
...
4
votes
0
answers
193
views
Prevent conversion from derived class to 3rd-party base class while retaining public inheritance
As the title says, I'd like to prevent implicit conversions from a derived class to its base class while retaining public inheritance. I do not have access to the base class implementation. Example:
//...
7
votes
4
answers
1k
views
How can I prevent implicit conversion among `std::function`s with differenent argument types?
I'm trying to bind some ta-lib functions and then callback.
Here is the simplified sample code:
#include <functional>
#include <type_traits>
#include <cstdint>
struct DataChunk {
...
1
vote
1
answer
112
views
Traversing structs using pointer++
This might be a dumb question but I'm just learning C.
I have declared:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct STRUCTURE{
char name[30];
}...
1
vote
2
answers
414
views
MPLABX XC8 Compiler - implicit signed to unsigned conversion?
Why am I getting :
(373)implicit signed to unsigned conversion
by doing:
fan_on_hh = hh + fan_hh_increment
All fan_on_hh, hh and fan_hh_increment are unsigned char.
This post suggests to do this:
...
0
votes
1
answer
846
views
Snowflake SQL, converting number YYYYWW into date
in snowflake i have numeric column with values like 202201, 202305,202248 that refers to year week combination. How can i convert it into first or last day of tha week?
for example 202251 will be '...
5
votes
1
answer
95
views
Why did newer compilers start accepting this template function call?
The following small C++ program involving a call to the template function std::atomic_fetch_add() fails to compile in godbolt for x86-64 clang versions less than 9.0 and gcc versions less than 9.1,
in ...
1
vote
1
answer
194
views
How can a void pointer hold data meant for non pointer variables? [duplicate]
I was practicing with void pointers when this code successfully compiled:
#include <stdio.h>
int main()
{
void *x = (void*) 576;
int *y = x;
printf("%d\n", y);
return ...
0
votes
2
answers
82
views
If int array variable return address of first element of int array then why char array variable not return address of first element?
Here, i attached code image
how it treat in char array?
If image is not clear, then refere this code
#include <stdio.h>
int main() {
char c[3] = {'s', 'a', 'h'};
int a[3] = {1, 2, 3};
...
0
votes
2
answers
115
views
Slick Futures converted into Promises
I am starting to develop in Scala, so I started witha really simple RESTful API using AKKA HTTP actors and then wanted to add a PostgreSQL database to "close up" the project. The thing is ...
0
votes
0
answers
139
views
Class with implicit operator to initialize with default value in method parameter C#
I have a class where I used implicit operator to initialize the class when string value assigned like this
MyClass db = "";
My class is
public class MyClass
{
public static implicit ...
2
votes
0
answers
204
views
Scala3 implicit conversion not working with opaque types (not true)
EDIT 2 - BEGIN: What I have not verified, and I should have, was if the conversion of my example works for regular types. And it doesn’t neither. So, the title and all my post is surely wrong.
Sorry ...
0
votes
0
answers
70
views
Failed implicit conversion from Object<T> to Object<const T>
As practice I tried to make a wrapper around raw pointers to have cleaner memory management when using CUDA. Basically I made a PointerBase template that has a PointerBase specialization for const ...
0
votes
0
answers
74
views
Is it possible to implicitly cast a generic type?
I'm working with a function that takes a list of email address records and returns the appropriate one for the use case. This list is passed to the function as an List[Map[String, String]], and the ...
0
votes
3
answers
169
views
Do format specifiers perform implicit type conversion?
#include <stdio.h>
int main(void) {
int x = 5;
int y = &x;
printf("Signed Value of Y: %d \n", y);
printf("Unsigned Value of Y: %u", y);
return 0;
}
...
1
vote
1
answer
130
views
Is this considered as an explicit cast or an (implicit) conversion?
As I am working on a topic related to MISRA, I had some doubts about this line of code:
int *a = (int *) malloc( 12 );
as rule 11.5 [A] "A conversion should not be performed from pointer to void ...
1
vote
1
answer
57
views
Implicit versus Explicit cast with parenthesis wrapper
The implicit cast:
FooType Foo = (FooType)someParameter;
The Explicit cast:
FooType Foo = someParameter as FooType;
However, Does double wrapping an implicit cast make it an explicit cast if ...
5
votes
1
answer
232
views
Difference in behavior of pointer-to-member access operators
In C++, I'm searching for the crucial sections of the standard
explaining the subtle difference in behavior I've observed between the
language's two pointer-to-member access operators, .* and ->*.
...
3
votes
3
answers
156
views
Rounding through type ascription
I would like to introduce a custom class, say Decimal2, so that I would be able to round through type ascription:
val x: Decimal2 = 1.2345
// 1.24
So far I've tried this:
class Decimal2(val value: ...
2
votes
1
answer
89
views
Implicitly calling constructor
I have this exam question that says :
Bar can be properly constructed with ...
and I have to choose the correct option(s):
class Bar{
public:
Bar(std::string);
Bar(int a=10,double b=7.10, ...
0
votes
1
answer
121
views
Why is there no implicit conversion sequence from int to vector<double>?
Regarding
vector<double> v2 = 9; //error: no conversion from int to vector
Is there no implicit conversion sequence of the copy-initialization from
int
to
vector<double>
because
std::...
0
votes
1
answer
155
views
Cast array returned from Oracle stored procedure
I am having difficulty reading values from the following object type array returned from Oracle stored procedure
var arrUtil = cmd.Parameters["UTILBYDAY"].Value;
The arrUtil array is of the ...
3
votes
0
answers
41
views
C++20 function overloading with references [duplicate]
I'm diving into the implicit conversions of C++20, and came up with this example:
#include <iostream>
void f(int a){ std::cout << 1; }
void f(int &a){ std::cout << 2; }
int ...
0
votes
1
answer
246
views
What it means the 6.3.1.8 section of the C standard?
the 6.3.1.8 section of the C standard says the next:
.
.
.
Many operators that expect operands of arithmetic type cause conversions and yield result types in
a similar way. The purpose is to ...
0
votes
0
answers
59
views
Which are the C Standard rules for implicit type coversion?
i fund a post here in SO, that states some rules for implicit type conversion:
— If both operands have the same type, no further conversion is needed.
— Otherwise, if both operands have signed ...
0
votes
1
answer
76
views
How does the implicit conversion for int2double come in scope
The following conversion works because of int2double implicit conversion
scala> val d: Double = 2
d: Double = 2.0
prior to 2.10, this implicit conversion was part of Predef object and was thus ...
1
vote
1
answer
72
views
Is there a conversion from pointer to array? [duplicate]
For example, for the following code, I know that p is a pointer, which points to the first element of the array arr, and I also know that the array will degenerate into an array under certain ...
0
votes
1
answer
72
views
How to create pointer to 2d array of chars?
I am having trouble declaring pointer to 2d variable of chars...
const char * d1 [][2] =
{
{ "murderer", "termination specialist" },
{ "failure", "non-...
1
vote
3
answers
76
views
C Language: I try passing 2d string to function and need to use pointer, but it shows the warning
I'm a university student. and the teacher wants me to pass multiple strings to function. The answer output is correct but I wonder what the warning is why it shows and how to fix it in my case.
I try ...
1
vote
1
answer
1k
views
Why does QColor use 32-bit signed int to represent e.g. rgba values?
QColor can return rgba values of type int (32-bit signed integer). Why is that? The color values range from 0-255, don't they? Is there any situation where this might not be the case?
I'm considering ...
1
vote
2
answers
210
views
Model custom type as pointer or as reference?
In addition to pointers, C++ also provides references that behave similarly. In addition to these built-in types, it also gives the option to construct custom types that mimic this behavior.
Take ...
8
votes
1
answer
292
views
Prefer one type convert into another through implicit constructor or implicit conversion operator?
Assume we have procedure void f(X2);. Further assume we have types X1 and X2 that do not share an inheritance hierarchy.
We want to call it like this: f(X1{}) and have X1 implicitly convert into X2. ...
1
vote
1
answer
607
views
Printing 1D array using pointer in C
I want to print the data of array by using pointers so I try to save the address of array in the pointer. But the pointer doesn't print the data. I will print a second array as well later on so there ...
0
votes
1
answer
46
views
How to pass pointer to array of struct into function
I tried making code to simulate boss fights. Firstly initialize the array of struct, making pointer out of it, and passing it into function.
#include <stdio.h>
struct machine_gun{
char name[...
0
votes
3
answers
81
views
Is it possible to take user input for a 2D array using pointer names in C?
I want to take user input for a 2D array using pointer name
Let's say I have a 2D array named arr1[3][3] and the pointer variable name is ptr1. Is it possible use scanf with the pointer variable name?...
0
votes
2
answers
79
views
Pointer initialization/dereferencing
What is the difference between
int(*a)[5];
int b[5] = { 1, 2, 3, 4, 5 };
i = 0;
a = &b;
for (i = 0; i < 5; i++)
printf("%d\n", *(*a+i));
and
int b[5] = { 1, 2, 3, 4, 5 };
int *y ...
0
votes
1
answer
245
views
C++20: Narrowing between T* to bool
One of the features of C++20 is Converting from T* to bool should be considered narrowing but perhaps I am not familiar with the history of this and trying to wrap my head around it in terms of what's ...
-1
votes
1
answer
145
views
What is the use for this Condition in the for loop for(int i = 0; i < m and n; i++)? [closed]
I encountered a question in competitive programming and the solution for that include a for loop with a syntax like
for(int i = 0; i < m and n; i++){
//Do Something
}
When I changed the ...