Questions tagged [explicit]

In C++ specifies constructors and conversion operators that don't allow implicit conversions or copy-initialization. In C# declares a user-defined type conversion operator that must be invoked with a cast. For MS SQL Server for-xml-EXPLICIT mode use the [for-xml-explicit] tag

405 questions
3
votes
2 answers

Entity Framework Explicit Loading Example

I'm trying this part of codes on "northwind" database.However I'm getting DataBind error protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { GetSpecificCustomer(); } } …
Ahmet Güzel
  • 95
  • 1
  • 9
3
votes
2 answers

Is it possible to CreateInstance of object with protected constructor?

Greetings fellow members, the situation in question is such: public abstract class BaseClass { protected BaseClass() { // some logic here } protected BaseClass(Object parameter) : this() { // some more logic …
SmartK8
  • 2,616
  • 1
  • 29
  • 37
2
votes
2 answers

How to provide type arguments explicitly when calling generic method in Java?

Imagine the following code, written in C#: public class Provider { T GetValue(); // implementation skipped for brevity } // public class Converter { T2 Convert(T1 value);// implementation skipped for brevity } // public class…
Ivaylo Slavov
  • 8,839
  • 12
  • 65
  • 108
2
votes
2 answers

Explicit & Implicit Operator with Numeric Types & unexpected results

I have never done any extensive work with overloading operators, especially the implicit and explicit conversions. However, I have several numeric parameters that are used frequently, so I am creating a struct as a wrapper around a numeric type to…
psubsee2003
  • 8,563
  • 8
  • 61
  • 79
2
votes
1 answer

Program with explicit works in msvc but not in gcc

I learnt about the explicit keyword in c++ and its uses. Then for practice I wrote the following program that works with MSVC but not with gcc and clang. Demo. class Testing { public: explicit Testing() = default; }; int main() { …
Alex
  • 318
  • 1
  • 14
2
votes
1 answer

Explicit copy constructor of a parameter passed via std::async

In the following program foo function is executed asynchronously and its argument of type A is copied inside async by value: #include struct A { A() = default; explicit A(const A &) = default; }; void foo(const A &) {} int main()…
Fedor
  • 17,146
  • 13
  • 40
  • 131
2
votes
1 answer

How is that an explicit constructor is used in an implicit conversion

I am learning about explicit keyword in C++ using the resources listed here and as this post says: Prefixing the explicit keyword to the constructor prevents the compiler from using that constructor for implicit conversions. Now I wrote the…
Kal
  • 475
  • 1
  • 16
2
votes
3 answers

Defining your own explicit conversions

Suppose, if a conversion from one type another type is not available through explicit casts e.g static_cast, Would it be possible to define explicit conversion operators for it? Edit: I'm looking for a way to define explicit conversion operators for…
Jason
  • 23
  • 1
  • 4
2
votes
1 answer

C++: Compilation error with explicit keyword

The following code throws compilation error: #include class Option { Option() { printf("Option()\n"); }; public: explicit Option(const Option& other) { printf("Option(const)\n"); *this = other; } …
Saksham Jain
  • 537
  • 3
  • 14
2
votes
1 answer

How to set property of explicitly implemented interface?

I've this code snippet: public interface Imy { int X { get; set; } } public class MyImpl : Imy { private int _x; int Imy.X { get => _x; set => _x = value; } } class Program { static void Main(string[] args) …
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
2
votes
2 answers

Specify the assembly explicitly?

I am getting this ambiguous reference error with some software that came from a vendor. The problem is, I need to keep both DLLs in my project, because various parts of it use code from both. So... I need to know the syntax for explicitly specifying…
Jasmine
  • 4,003
  • 2
  • 29
  • 39
2
votes
0 answers

explicit deep link navigation backstack issue

Lets take an app with 2 activities MainActivity and Activity2. MainAct is the launcher activity. Activity2 contains a default navhost fragment having a navgraph with two fragments, fragment1(start-destination), fragment2. When starting MainActivity…
IulianT
  • 350
  • 1
  • 3
  • 13
2
votes
1 answer

Uniform initialization occurs implicitly, even though the int cast operator is declared with the explicit keyword. What is the reason?

#include using namespace std; class Test { private: mutable int val{}; public: static constexpr int MAX{ 5 }; public: Test() = default; Test(int i) : val{ i } {} ~Test() { cout << "~Test()" << endl; } explicit…
김정연
  • 47
  • 2
2
votes
3 answers

Will the pointer to a template member function inside a constructor force instantiation?

Consider the following header file: // Foo.h class Foo { public: template void read(T& value); }; It seems that assigning a pointer to Foo::read in the constructor of a class, of which variable is then declared, cause…
Daniel Langr
  • 22,196
  • 3
  • 50
  • 93
2
votes
1 answer

explicit copy constructor for template generator error

Being porting old code from MSVS2003 to MSVS2017 and ran into problems. The following code (an excerpt) is compiled fine under MSVS2003 and fails under MSVS2017: template class TTT { public: template
mdod
  • 23
  • 6