What is the meaning of “operator bool() const”

Member functions of the form operator TypeName() are conversion operators. They allow objects of the class type to be used as if they were of type TypeName and when they are, they are converted to TypeName using the conversion function. In this particular case, operator bool() allows an object of the class type to be … Read more

Implicit type promotion rules

C was designed to implicitly and silently change the integer types of the operands used in expressions. There exist several cases where the language forces the compiler to either change the operands to a larger type, or to change their signedness. The rationale behind this is to prevent accidental overflows during arithmetic, but also to … Read more

Why can I pass 1 as a short, but not the int variable i?

The first two are constant expressions, the last one isn’t. The C# specification allows an implicit conversion from int to short for constants, but not for other expressions. This is a reasonable rule, since for constants the compiler can ensure that the value fits into the target type, but it can’t for normal expressions. This … Read more

Can we define implicit conversions of enums in c#?

There is a solution. Consider the following: public sealed class AccountStatus { public static readonly AccountStatus Open = new AccountStatus(1); public static readonly AccountStatus Closed = new AccountStatus(2); public static readonly SortedList<byte, AccountStatus> Values = new SortedList<byte, AccountStatus>(); private readonly byte Value; private AccountStatus(byte value) { this.Value = value; Values.Add(value, this); } public static implicit … Read more

Objective-C implicit conversion loses integer precision ‘NSUInteger’ (aka ‘unsigned long’) to ‘int’ warning

The count method of NSArray returns an NSUInteger, and on the 64-bit OS X platform NSUInteger is defined as unsigned long, and unsigned long is a 64-bit unsigned integer. int is a 32-bit integer. So int is a “smaller” datatype than NSUInteger, therefore the compiler warning. See also NSUInteger in the “Foundation Data Types Reference”: … Read more

Static implicit operator

This is a conversion operator. It means that you can write this code: XmlBase myBase = new XmlBase(); XElement myElement = myBase; And the compiler won’t complain! At runtime, the conversion operator will be executed – passing myBase in as the argument, and returning a valid XElement as the result. It’s a way for you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)