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
Questions tagged [explicit]
405 questions
4
votes
5 answers
Explicit Casting Generic to Another Type in C#
I have the following code for C++, in a templated class that represents a point. I would like to translate it into C#:
template
class Point
{
public:
T x;
T y;
T z;
template explicit Point(const…

Michael Kintscher they-them
- 703
- 7
- 19
4
votes
1 answer
error: no matching function for call to ... at return statement
I'm using GCC7 on Qt 5.9.4 on openSUSE Leap 15.
I have the following class:
class ManSuppProps : public QObject
{
Q_OBJECT
public:
explicit ManSuppProps(QString parentName);
explicit ManSuppProps(){}
explicit ManSuppProps(const…

Megidd
- 7,089
- 6
- 65
- 142
4
votes
2 answers
Android app licencing fatal exception: Service Intent must be explicit
I am migrating an older Android app from Eclipse to Android Studio.
Everything was working fine on older versions of Android about 3-4 years ago.
Now, when I run the app on Android 7.0 the android.vending.licensing is producing the following…

EasyCoder
- 71
- 7
4
votes
0 answers
When to use explicit constructors (C++11)
I have read about the usage of explicit in constructors and some of its possible outcomes. There are many posts available at stack overflow but my primary problem is that I need some concrete points to bear in mind when designing a constructor and…

fllprbt
- 103
- 1
- 10
4
votes
2 answers
Explicit template instantiation with member template function
I have a template class with a template member function. I want to explicitly instantiate the class to avoid a drastic compilation slowdown. I am using g++ 4.1.2. I get ambiguous template specialization errors from the compiler. This the shortest…

Vagabond
- 157
- 1
- 1
- 7
4
votes
2 answers
Explicit constructor and static_cast
struct Foo
{
explicit Foo(int a):m(a){}
int padd1, m, padd2;
};
void Bar(Foo){}
int main()
{
Bar(11); // OK, gives error
auto x = static_cast(37);
x.m;
}
Is it ok, that static_cast construct Foo object even though its…

relaxxx
- 7,566
- 8
- 37
- 64
4
votes
1 answer
Preventing implicit conversion of some arguments in a templated member function
Currently I have a member function defined as such:
template bool updateParameter(const std::string& name, const T& data);
With an overload for pointers.
template bool updateParameter(const std::string& name, T* data);
I…

Daniel Moodie
- 357
- 1
- 10
4
votes
2 answers
C++ implicit and explicit inheritance constructor calls
I have a question about implicit and explicit calls to a base constructor. If we have a class hierarchy like this:
class Person{
protected:
std::string m_name;
public:
Person(std::string& _name) : m_name(_name){std::cout <<…
user4165455
4
votes
1 answer
C++ explicit constructor and cast
In the book Effective C++, Item 27
class Widget {
public:
explicit Widget(int size);
...
};
void doSomeWork(const Widget& w);
doSomeWork(Widget(15)); // create Widget from int
// with function-style cast
I'm not sure exactly…

Sherry He
- 43
- 4
4
votes
2 answers
For structs, do I have to call the constructor explicitly in C#?
The question is about the structs. When I declare a struct type variable/object (don't know which one suits better) or an array or list of structs, do I have to call the constructor explicitly like objects or just declaring will suffice like…

Gulshan
- 3,611
- 5
- 35
- 46
4
votes
2 answers
C++ how do i keep compiler from making implicit conversions when calling functions?
Here's the deal:
When i have a function with default arguments like this one
int foo (int a, int*b, bool c = true);
If i call it by mistake like this:
foo (1, false);
The compiler will convert false to an int pointer and call the function with b…

Jean-Luc Nacif Coelho
- 1,006
- 3
- 14
- 30
4
votes
1 answer
Why implicit conversion is occurring in "if expression" although it should be explicit conversion
This code is not supposed to compile , so why it is ?
what is the principle of the context in if expression ?
class B {
public:
B() {}
explicit operator bool () {}
};
int main (){
B Bp;
//bool check = Bp // error
…

user2321876
- 105
- 1
- 8
4
votes
1 answer
Why is the wrong ctor being called?
I have code that works as expected:
EscapedString es("Abc&def");
EscapedString es2("");
es2 = es; // es2 == Abc%26def
And code that doesn't work as expected:
EscapedString es("Abc&def");
EscapedString es2 = es; // es == Abc%2526def
In the…

boatcoder
- 17,525
- 18
- 114
- 178
4
votes
2 answers
Multiple system explicit converters are allowed, but mutiple user explicit converters are not. Why?
If I have this code, this will compile and work as it should:
class MyNumber // Just a class.
{
static public explicit operator MyNumber(byte b)
{
return new MyNumber();
}
}
Decimal d = new Decimal();
MyNumber c1 =…

Martin Mulder
- 12,642
- 3
- 25
- 54
4
votes
2 answers
Function template explicit specialization c++
My book mentions two ways for explicit specialization:
template <> void Swap (int &, int &);
template <> void Swap(int &, int&);
what is the difference between both? when to use one and when to use the other? what is exactly the <> after the…

jazzybazz
- 1,807
- 4
- 17
- 21