explicit

Strings and ints, implicit and explicit

坚强是说给别人听的谎言 提交于 2019-12-01 14:45:14
问题 Had a coworker ask me this, and in my brain befuddled state I didn't have an answer: Why is it that you can do: string ham = "ham " + 4; But not: string ham = 4; If there's an implicit cast/operation for string conversion when you are concatenating , why not the same when assigning it as a string? (Without doing some operator overloading, of course) 回答1: When concatenating the compiler turns the statement "ham" + 4 into a call to String.Concat , which takes two object parameters, so the value

@Autowired doesn't work if component-scan removed

*爱你&永不变心* 提交于 2019-12-01 03:42:20
I'm facing the problem, that the annotation @Autowired doesn't work anymore (in all Java classes that uses this annotation) if I remove the component-scan tag from config <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema

@Autowired doesn't work if component-scan removed

只愿长相守 提交于 2019-12-01 00:38:38
问题 I'm facing the problem, that the annotation @Autowired doesn't work anymore (in all Java classes that uses this annotation) if I remove the component-scan tag from config <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans

explicit operator bool error

坚强是说给别人听的谎言 提交于 2019-12-01 00:01:00
问题 I get the Compiler Error C2071 when I try to implement the explicit operator bool : class C { public: explicit operator bool() const { return !!*this; } }; Why? How can I solve this problem? I'm using Visual Studio 2012 RC. 回答1: Visual Studio 2012 does not support explicit conversion operators, see C++11 Features in Visual C++ 11. These articles talk about the safe bool idiom : http://www.artima.com/cppsource/safebool.html http://en.wikibooks.org/wiki/More_C++_Idioms/Safe_bool 回答2: If you

Explicit integral could not be found

不想你离开。 提交于 2019-11-30 19:10:19
问题 I am getting a well-known error of "Explicit integral could not be found" if I try to evaluate following integral syms z; funz=1./(1+exp((z*z-0.5)/0.1)); Integ2=int(funz,z,0,inf) I get the warning: Warning: Explicit integral could not be found. Integ2 = int(1/(exp(10*z^2 - 5) + 1), z == 0..Inf) Mathematica evaluates this integral to 0.693 . I have tried replacing lower integration limit to some small finite number (0.001) but that doesn't help. Please help in identifying the fix for this

Is it possible to infer template parameters of tuple from brace-type initialization?

不想你离开。 提交于 2019-11-30 15:40:52
In this example, is it possible to allow the deduction of the template parameters type of the tuple ? #include<tuple> #include<string> template<class T1, class T2> void fun(std::tuple<T1, T2> t, std::string other){} int main(){ fun(std::tuple<double, int>(2.,3), std::string("other")); // ok fun(std::make_tuple(2.,3), std::string("other")); // ok, but trying to avoid `make_tuple` fun({2.,3},std::string("other")); // desired syntax but // giving compilation error: candidate template ignored: couldn't infer template argument 'T1' void fun(std::tuple<T1, T2> t) } I added the second argument other

What changes to C++ made copy initialization work for class with explicit constructor?

蓝咒 提交于 2019-11-30 08:20:34
Consider this code: struct X{ explicit X(){} explicit X(const X&){} }; void foo(X a = X()){} int main(){} Using C++14 standard, both GCC 7.1 and clang 4.0 rejects the code, which is what I expected. However, using C++17 ( -std=c++1z ), they both accept the code. What rule changed? For both compilers to exhibit this same behavior, I doubt this to be a bug. But as far as I can tell, the latest draft still says, default argument uses the semantics of copy-initialization 1 . Again, we know that explicit constructors will only allow direct initialization 2 . 1 : dcl.fct.default/5 ; 2 : class.conv

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

蓝咒 提交于 2019-11-30 05:12:15
问题 What is the usage of these operators? 回答1: Basically when you want to provide conversions between types. LINQ to XML provides good examples... There's an implicit conversion from string to XName, so you can write: XName name = "element"; but there's an explicit conversion from XAttribute to int (and many other types) so you have to include a cast in your code: int value = (int) element.Attribute("age"); Think very carefully before providing implicit conversions - they're rarely a good idea;

C++ always use explicit constructor [closed]

依然范特西╮ 提交于 2019-11-29 20:17:51
After reading the following blog : http://xania.org/200711/ambiguous-overloading I started asking myself "should I not always explicit define my constructors?" So I started reading more than found out this article : http://www.sjbrown.co.uk/2004/05/01/always-use-explicit/ Which shows another example, and also explains his thoughts behind it. But of course this is one blogger's thoughts. I would be happy to hear from some of you,what your thought on the manner, what is your experience with the subject and a few example for either way would be nice. The traditional wisdom is that constructors

Explicitly disabling UIView animation in iOS4+

随声附和 提交于 2019-11-29 17:35:02
问题 I have been reading that Apple recommends to use block-based animations instead of CATransaction Before, I was using this code to disable animations: [CATransaction begin]; [CATransaction setDisableActions: YES]; // !!! resize [CATransaction commit]; Is there a new recommended method to do this, or is this still okay? 回答1: [UIView setAnimationsEnabled:NO]; //animate here [UIView setAnimationsEnabled:YES]; 回答2: For iOS 7 and above this can now be accomplished with: [UIView