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
5
votes
1 answer

Construct tuple by passing the same argument to each element with explicit constructor

The following works fine on Visual C++ 2015 Update 2. Note that A is non-copyable and A::A is explicit. #include #include struct A { explicit A(int i) { std::cout << i << " "; } // non-copyable …
isanae
  • 3,253
  • 1
  • 22
  • 47
5
votes
2 answers

Pros / Cons of Tacit Programming in J

As a beginner in J I am often confronted with tacit programs which seem quite byzantine compared to the more familiar explicit form. Now just because I find interpretation hard does not mean that the tacit form is incorrect or wrong. Very often…
user1202733
  • 623
  • 4
  • 10
5
votes
3 answers

Explicit C# interface implementation of interfaces that inherit from other interfaces

Consider the following three interfaces: interface IBaseInterface { event EventHandler SomeEvent; } interface IInterface1 : IBaseInterface { ... } interface IInterface2 : IBaseInterface { ... } Now consider the following class that…
anthony
  • 40,424
  • 5
  • 55
  • 128
5
votes
2 answers

Do you have to explicitly create instance of form in VB.NET?

If a project contains a Form class, can the form be shown by: Form1.Show or does an instance of the form need to be created first? Dim frm As New Form1 frm.Show
CJ7
  • 22,579
  • 65
  • 193
  • 321
5
votes
1 answer

explicit template instantiation: MSVC vs. GCC

I'm trying to deal with namespaces & templates in C++. I can get the following code to compile in MSVC (no warnings or errors), but am having no luck at all with various permutations with CYGWIN/GCC. Any help would be appreciated. In the header…
Rob Bryce
  • 261
  • 2
  • 7
5
votes
3 answers

Explicit Loading of DLL

I'm trying to explicitly link with a DLL. No other resources is available except the DLL file itself and some documentation about the classes and its member functions. From the documentation, each class comes with its own member typedef example:…
justin
  • 243
  • 2
  • 6
  • 15
5
votes
3 answers

Why certain implicit type conversions are safe on a machine and not on an other?? How can I prevent this cross platform issues?

I recently found a bug on my code that took me a few hours to debug. the problem was in a function defined as: unsigned int foo(unsigned int i){ long int v[]={i-1,i,i+1} ; . . . return x ; // evaluated by the function but…
lucacerone
  • 9,859
  • 13
  • 52
  • 80
5
votes
2 answers

Should I explicitly define the values my enumerated constants

I've heard before that I should simply let the compiler choose which values to assign for enumerated constants if I'm not doing something clever like using the values as bitmasks. If I'm just using enumeration values for more explicit code…
Joel B
  • 12,082
  • 10
  • 61
  • 69
4
votes
1 answer

How does the 'explicit' keyword affect C++ copy constructors and function parameters?

The "explicit" keyword to modify the copy constructor can cause problems. Objects passed as function parameters are particularly susceptible to these issues. here are my codes: #include #include class Pig{ public: …
Andrés
  • 41
  • 2
4
votes
1 answer

Why does shared_ptr p; p=nullptr; compile?

Since the constructor of std::shared_ptr is marked as explicit one, so expressions like auto p = std::make_shared(1); p = new int(6); is wrong. My question is why does std::make_shared(1); p = nullptr; compile? Here is the aforementioned…
John
  • 2,963
  • 11
  • 33
4
votes
4 answers

Why std::pair calls explicit constructors in assignment

Consider the following code: #include #include struct Base { int baseint; }; struct Der1 : Base { int der1int; Der1() : der1int(1) {} explicit Der1(const Base& a) : Base(a), der1int(1) { std::cerr <<…
Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79
4
votes
2 answers

QDialog explicit constructor without argument - how to use correctly?

I experienced this with a derived class, but it's the same with QDialog base class: when I do QDialog dialog(); dialog.exec(); the compiler complains J:\...\mainwindow.cpp:-1: In member function 'void…
friede
  • 137
  • 8
4
votes
1 answer

Android Override Explicit Intent

My app needs to have a intent-filter that responds to a Intent that has it's component set (a explicit intent.) Here is a example. Intent i = new…
Isaac Waller
  • 32,709
  • 29
  • 96
  • 107
4
votes
2 answers

Make argument explicit?

explicit can be used on eg. a constructor or conversion function to avoid implicitly calling that constructer/conversion - in short. Im interested in if it is possible to make a single argument explicit somehow (short of roling a new type) ? perhaps…
darune
  • 10,480
  • 2
  • 24
  • 62
4
votes
1 answer

What conversions does the conversion constructor do if an object is created and assigned a value?

If I have a class with a constructor like this: class A { public: A(int e) { // Use the `e` value } }; And if I make calls like this: int main() { A obj = 'c'; } What conversions would take place? Would a conversion to type A take…
Amith
  • 730
  • 6
  • 22