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

c++ cli interface event explicit implementation

I am trying to convert c# code into c++/cli. Everything went smoothly until i started translating interface event explicit implementations into c++/cli syntax. Let's say in c# i have this interface public interface Interface { public event…
edwabr123
  • 97
  • 9
4
votes
2 answers

C++ Explicit Constructor

I have a class with 2 constructors. explicit MyClass(size_t num); template MyClass(T myObj); And I want that whenever I make MyClass obj( 30 ); The first constructor will be called, And on implicit constructors and MyClass obj =…
Taru
  • 2,562
  • 4
  • 22
  • 30
4
votes
2 answers

Implicit conversons in Scala and C#

Implicit conversions seem to be a major and controversial feature of Scala, while they seem to have far less prominence in C#. What's the difference between them in the two languages? Is there anywhere I'm forced to use implicits in Scala, or can I…
Rich Oliver
  • 6,001
  • 4
  • 34
  • 57
3
votes
2 answers

How do I explicitly refer to this template member?

Template members may be implicitly referred to if they are the only member of a template, and if they share the template's name: template foo(int number) { immutable int foo = number; } void main() { writeln(foo!(123)); // Okay. } But what…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
3
votes
1 answer

Explicit template specialization

I hate to ask such a general question, but the following code is a exercise in explicit template specialization. I keep getting the error: c:\users\***\documents\visual studio 2010\projects\template array\template array\array.h(49): error C2910:…
David
  • 1,398
  • 1
  • 14
  • 20
3
votes
1 answer

Why is gnu make ignoring my explicit pattern rule and using a built-in implicit rule instead?

My makefile has this rule/recipe: %o: %cpp Makefile g++ -Wall -Wextra -MMD -MP -O2 -c -o $@ $< This worked fine until I upgraded Cygwin recently and got Make 3.82.90 (previous version was probably 3.81). Now with make 3.82, it ignores my rule…
Dan
  • 5,929
  • 6
  • 42
  • 52
3
votes
5 answers

Can I rename an implemented method in Java?

I have a class which is implementing an interface, and one of the methods is called onClick. Is there a way to implement the onClick that the interface wants but name it something else? Something like (and I'm making this up): public void…
Mendhak
  • 8,194
  • 5
  • 47
  • 64
3
votes
1 answer

Why here template Vector3 cannot convert to Vector3?

It seems quite weird. Here you can see the error message is that a convert happens between one type and it fails. If I remove the explicit modifier from Vector3's copy constructor it is fine, no error. Could someone explain why? I'm…
3
votes
2 answers

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 MyClass { A(int) {} }; A a = 1; If I follow…
DDS
  • 2,340
  • 16
  • 34
3
votes
2 answers

Why doesn't the `explicit` keyword prevent a `char` from being converted into an `int`?

From what I understand, in the following code, explicit A(int a) should prevent A b('g'); to use the int constructor: #include class A { public: int x; char *y; A() : x(0) {} explicit A(int a) : x(a)…
H-005
  • 467
  • 3
  • 15
3
votes
2 answers

What actually happens when copy initializing in C++?

Consider the following code: #include using namespace std; class A{ public: A()=default; A(int a){cout<<"A(int) called"<
sakugawa
  • 117
  • 5
3
votes
4 answers

My explicit instantiation of template class seems doesn't work

I wrote a short program to test the template class's explicit instantiation as follows: #include template struct less_than_comparable { friend bool operator>=(T const& a, T const& b) { return !(a < b); …
Brooks Xi
  • 33
  • 3
3
votes
1 answer

Explicitly assign any type in typescript

Currently we are migrating our codebase to typescript and we have many places with any type. So I am trying to enforce explicit setting variables as any. Here is example snippet. const a: string = 'h'; const b: any = 4; const message = a || b; //…
3
votes
1 answer

Behavior when both conversion constructor and operator are present and explicitness is involved

I have a piece of code where I have both conversion constructor and conversion operator. #include struct ClassFloat; struct ClassInt{ int value; ClassInt(int c) : value(c){std::cout << "From integer\n";}; ClassInt(ClassFloat…
jannarc
  • 93
  • 2
  • 8
3
votes
1 answer

How can I apply make a default constructor conditionally explicit?

Problem Suppose we have a (fictional) class template C with a conditionally explicit default constructor. The default constructor should be explicit if and only if std::is_same_v. A search on "[c++] conditionally explicit" returns this…
L. F.
  • 19,445
  • 8
  • 48
  • 82