Question: 1. (Explicit Constructors) Consider the following class: struct B { explicit B(int) {} explicit B(int, int) {} explicit operator int() const { return 0; }
1. (Explicit Constructors)
Consider the following class:
struct B
{
explicit B(int) {}
explicit B(int, int) {}
explicit operator int() const { return 0; }
};
Create a program to test the class. Which lines of code below compile and which ones do not? How would you modify the class to ensure that they do compile? Otherwise, how can these lines be modified so that the code compiles error free without modifying the class?
B b1 = 1;
B b2(3);
B b3{ 7,3 };
B b4 = (B)42;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
