Skip to main content
-1 votes
1 answer
98 views

Why does explicit default constructor prevent this from being constructed?

struct ExplicitDefaultConstructor { explicit ExplicitDefaultConstructor() {} }; struct Material { ExplicitDefaultConstructor a; int b; }; int main() { Material{.b = 2 }; } It's ...
Zebrafish's user avatar
  • 16.1k
3 votes
0 answers
67 views

conditional operator: inconsistency between implicit conversion sequence used for different compilers

This is a follow-up of this question: conditional operator expression with base and const derived class doesn't compile, why?. The core is cond ? [cv] T1() : [cv] T2() where, for instance T2 ...
Oersted's user avatar
  • 3,479
0 votes
2 answers
197 views

Why can't the constructor be called explicitly?

I was looking into creating a constructor to initialize an encapsulated std::array and came across a problem that the constructor of a copyable type (class A) could not be called explicitly. There are ...
ValeriyKarasikov's user avatar
0 votes
1 answer
47 views

How parameter type conversion in C++ operator works? [duplicate]

I am creating a new class VarDbl, which contains a few explicit constructors as well as a + operator: class VarDbl { ... explicit VarDbl(double value, double uncertainty); explicit VarDbl(...
CPW's user avatar
  • 189
1 vote
1 answer
158 views

Is there any reason to mark a constructor of an abstract class as explicit

In the following example, my class is abstract due to the abstract method run. I also have a constructor from another type. I always mark constructor having only 1 argument as explicit, except when I ...
Caduchon's user avatar
  • 5,278
0 votes
0 answers
1k views

error: use of deleted function operator=(&&) with std::optional

I got myself an error sprouting from std::optional. Now when trying to reconstruct it, there seems to be something going on with defaulted ctors that I don't yet understand. Consider the following ...
glades's user avatar
  • 5,344
0 votes
1 answer
109 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::...
CosmicHusky's user avatar
9 votes
1 answer
219 views

Overload resolution between two constructors from std::initializer_list

In following program, struct C has two constructors : one from std::initializer_list<A> and the other from std::initializer_list<B>. Then an object of the struct is created with C{{1}}: #...
Fedor's user avatar
  • 24.1k
-1 votes
2 answers
1k views

C++ copy assignment operator behaviour

I used the code below to test the behaviour of copy assignment operator: #include <iostream> using namespace std; int group_number = 10; // Global class Player { public: explicit Player(...
ZR_xdhp's user avatar
  • 371
6 votes
1 answer
665 views

Why is my explicit constructor creating this ambiguity for my conversion operator?

I'm unable to figure out why my conversion operator is considering the explicit constructor. #include <utility> template <typename T = void> struct First { template <typename... ...
Richard Fabian's user avatar
3 votes
1 answer
225 views

Why is the converting constructor preferred to the conversion operator?

I have this class SmallInt that should represent a positive integer value in the range 0-255-inclusive: struct SmallInt{ explicit SmallInt(int x = 0) : iVal_( !(x < 0 || x > 255) ? x : ...
Itachi Uchiwa's user avatar
1 vote
1 answer
259 views

Can't add element into container<T> with emplace new if T has explicit constructor

I am writing a fixed size container type, with placement new. When I was testing it I figured it out my "emplace_back()" like function does not compile if the type T has explicit ctor. Here ...
thamas's user avatar
  • 315
3 votes
2 answers
2k views

C++ use of explicit suggested by cppcheck

Is using the cast constructor bad? Otherweise why a code quality checker (cppcheck in my case) would constantly suggest to add explicit before single parameter constructors? What if I want to do class ...
DDS's user avatar
  • 2,480
0 votes
1 answer
2k views

Is there really no explicit constructor of std::string from an std::string_view?

Some (many?) programmers who are introduced to both std::string_view and std::string ask themselves: "Why can I convert the latter into the former, but not the other way around?" One part ...
einpoklum's user avatar
  • 137k
0 votes
0 answers
105 views

To use parameterized constructor through explicit call

I am facing an error while writing this code so here in the below program code the obj1 and obj2 are called explicitly by using parameterized constructor But I am not able to get the output saying an ...
user avatar

15 30 50 per page
1
2 3 4 5