explicit

[WPF] Binding UpdateSourceTrigger=Explicit, updates source at program startup

I have following code: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <TextBox Text="{Binding Path=Name, Mode=OneWayToSource, ...

Is there ever an excuse for throwing an Exception from an implicit conversion?

From MSDN: By eliminating unnecessary casts, implicit conversions can improve source code readability. However, because implicit conversions can occur without the programmer's specifying them, care must be taken to prevent unpleasant surprises. In general, implicit conversion operators should never throw exceptions and never lose inf...

FOR XML EXPLICIT

Hi, Say I have this setup: -- tables declare @main table (id int, name varchar(20)) declare @subA table (id int, mid int, name varchar(20)) declare @subA1 table (id int, subAid int, name varchar(20)) declare @subA2 table (id int, subAid int, name varchar(20)) declare @subB table (id int, mid int, name varchar(20)) -- sample data inser...

Why is "explicitness" considered a Good Thing?

I often hear people praise languages, frameworks, constructs, etc. for being "explicit". I'm trying to understand this logic. The purpose of a language, framework, etc. is to hide complexity. If it makes you specify all kinds of details explicitly, then it's not hiding much complexity, only moving it around. What's so great about exp...

C#: Explicit Namespace not Appearing in Generated XML.

Given the following C# code to generate an XML file: XmlDocument requestXML = new XmlDocument(); XmlDeclaration declaration = requestXML.CreateXmlDeclaration( "1.0", "utf-8", null ); requestXML.AppendChild( declaration ); XmlElement soapEnvelope = requestXML.CreateElement( "soap:Envelope" ); soapEnvelope.SetAttrib...

C++ explicit constructors and iterators

Consider the following code: #include <vector> struct A { explicit A(int i_) : i(i_) {} int i; }; int main() { std::vector<int> ints; std::vector<A> As(ints.begin(), ints.end()); } Should the above compile? My feeling is that it should not, due to the constructor being marked explicit. Microsoft Visual C++ agrees, g...

Explicitly passing a const object to an constructor which takes const reference to a polymorphic class

I got into a problem with my classes, passing a const object (polymorphic structure) to an explicit constructor which takes a const reference to the base class of that polymorphic structure. Here is the sample (this is not from my code, it is for explanation here) class Base { ... } class Derived:public Base { ... } class Problem { ...

When must we use implicit and explicit operators in C#?

What is the usage of these operators? ...

Why can't I use interface with explicit operator?

Hi, I'm just wondering if anyone knows the reason why you are not allowed to use interfaces with the implicit or explicit operators? E.g. this raises compile time error: public static explicit operator MyPlayer(IPlayer player) { ... } "user-defined conversions to or from an interface are not allowed" Thanks, ...

I want to extend std::string, but not for the reason you might think.

I have a method that effectively takes a string. However, there is a very limited subset of strings I want to use. I was thinking of typedef'ing std::string as some class, and call the functions explicit. I'm not sure that would work, however. Ideas? ...

Explicit behavior with checks vs. implicit behavior

I'm not sure how to construct the question but I'm interested to know what do you guys think of the following situations and which one would you prefer. We're working at a client-server application with winforms. And we have a control that has some fields automatically calculated upon filling another field. So we're having a field curre...

Why can't I call methods within a class that explicitly implements an interface?

Here's the story. I created an interface, IVehicle. I explicitly implemented the interface in my class, Vehicle.cs. Here is my interface: Interface IVehicle { int getWheel(); } here is my class: class Vehicle: IVehicle { public int IVehicle.getWheel() { return wheel; } public void printWheel(...

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 variables? ...

Can a single argument constructor with a default value be subject to implicit type conversion

I understand the use of the explicit keyword to avoid the implicit type conversions that can occur with a single argument constructor, or with a constructor that has multiple arguments of which only the first does not have a default value. However, I was wondering, does a single argument constructor with a default value behave the same...

Foo f = Foo(); // no matching function for call to 'Foo::Foo(Foo)' ... huh?!

class Foo { public: explicit Foo() {} explicit Foo(Foo&) {} }; Foo d = Foo(); error: no matching function for call to 'Foo::Foo(Foo)' I tried changing Foo(Foo&) to Foo(Foo) as the error suggests, which AFAIK is not a valid constructor, and sure enough I get: error: invalid constructor; you probably meant ‘Foo (const F...

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 implements both IInterface1 and IInterface 2: class Foo : IInterface1, IInterface2 { ...

Explicitly typing variables causes compiler to think an instance of a builtin type doesn't have a property, which it does

I narrowed the causes of an AS3 compiler error 1119 down to code that looks similar to this: var test_inst:Number = 2.953; trace(test_inst); trace(test_inst.constructor); I get the error "1119: Access of possibly undefined property constructor through a reference with static type Number." Now if I omit the variable's type, I don't ge...

Purpose of Explicit Default Constructors

I recently noticed a class in C++0x that calls for an explicit default constructor. However, I'm failing to come up with a scenario in which a default constructor can be called implicitly. It seems like a rather pointless specifier. I thought maybe it would disallow Class c; in favor of Class c = Class(); but that does not appear to b...

Explicit type conversion

I have read in a book that specifies this : //: C03:SimpleCast.cpp int main() { int b = 200; unsigned long a = (unsigned long int)b; } ///:~ "Casting is powerful, but it can cause headaches because in some situations it forces the compiler to treat data as if it were (for instance) larger than it really is, so it will occupy more spac...

Type casting Collections using Conversion Operators

The below code gives me User-defined conversion must convert to or from enclosing type, while snippet #2 doesn't... It seems that a user-defined conversion routine must convert to or from the class that contains the routine. What are my alternatives? Explicit operator as extension method? Anything else? public static explicit oper...