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,
...
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...
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...
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...
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...
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...
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
{
...
What is the usage of these operators?
...
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 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?
...
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...
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(...
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?
...
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...
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...
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
{
...
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...
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...
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...
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...