explicit

Explicit & Implicit Operator with Numeric Types & unexpected results

心不动则不痛 提交于 2019-12-11 02:46:18
问题 I have never done any extensive work with overloading operators, especially the implicit and explicit conversions. However, I have several numeric parameters that are used frequently, so I am creating a struct as a wrapper around a numeric type to strongly type these parameters. Here's an example implementation: public struct Parameter { private Byte _value; public Byte Value { get { return _value; } } public Parameter(Byte value) { _value = value; } // other methods (GetHashCode, Equals,

What is the effect of 'explicit' keyword on the Return Value Optimization (RVO)?

Deadly 提交于 2019-12-11 02:07:25
问题 Following code works perfectly fine (showing RVO): struct A { A (int) { cout << "A::A()\n"; } // constructor A (const A&) { cout << "A::A(const A&)\n"; } // copy constructor }; A foo () { return A(0); } int main () { A a = foo(); } Output: A::A() // --> which means copy constructor is not called If I mark the copy constructor as explicit : explicit A (const A&) { ... } Then the compiler errors out: explicit.cpp: In function ‘A foo()’: explicit.cpp:10:22: error: no matching function for call

Explicit Loading of DLL

故事扮演 提交于 2019-12-10 19:36:48
问题 I'm trying to explicitly link with a DLL. No other resources is available except the DLL file itself and some documentation about the classes and its member functions. From the documentation, each class comes with its own member typedef example: typedef std::map<std::string,std::string> Server::KeyValueMap, typedef std::vector<std::string> Server::String Array member enumeration example: enum Server::Role {NONE,HIGH,LOW} member function example: void Server::connect(const StringArray,const

Binding UpdateSourceTrigger=Explicit, updates source at program startup

我的梦境 提交于 2019-12-10 13:36:38
问题 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, UpdateSourceTrigger=Explicit, FallbackValue=default text}" KeyUp="TextBox_KeyUp" x:Name="textBox1"/> </Grid> public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void

Generic explicit cast failure C#

瘦欲@ 提交于 2019-12-10 03:47:01
问题 I've some issues with the following piece of code. I would like to explicit a string to an object, this is working perfectly fine, however, if this object is part of a generic class, this is failing with the following error exception: "Unable to cast object of type 'System.String' to type 'test.B'". Even though I've overloaded the the method. using System; using System.Collections.Generic; namespace test { class Program { static void Main(string [] args) { // These two cast perfectly fine. B

ASP.NET: explicit vs implicit localization?

ぃ、小莉子 提交于 2019-12-09 17:41:18
问题 To my mind the advantage of implicit localization over explicit localization is that if you have more than one property to localize for a given control, it's a more economical syntax. In the case where you just need to localize some text I use the asp:Localize control which only has a single property (Text) that renders to the UI. Is there a reason to use one over the other? Any style preference? Are there any speed differences? Implicit <asp:Localize ID="Localize1" runat="server" meta

Android app crashes when calling any explicit intent (like camera/gallery, call or share) on Samsung galaxy s3

北慕城南 提交于 2019-12-08 22:37:00
问题 I have compileSdkVersion and targetSdkVersion 23 and testing on Samsung galaxy s3. But whenever i open any third party app (explicit intent) like camera/gallery app or share intent (gmail, email) or dialer app and comeback to my app by pressing back button or (in case of camera/gallery app by selecting picture). App restarts from MainAcitivty (maybe it is getting crashed but it does not show any exception in logcat). Here is how i open intents: Call/Dial: Intent callIntent = new Intent(Intent

When do these load DLLs : Implicit Linking VS Explicit Linking

柔情痞子 提交于 2019-12-07 03:13:20
问题 I thought Implicit linking loads a DLL as soon as the application starts because it is also called "load-time dynamic linking". But I found some strange explanations below from the link here(https://msdn.microsoft.com/en-us/library/253b8k2c(VS.80).aspx). Implicit Linking Like the rest of a program's code, DLL code is mapped into the address space of the process when the process starts up and it is loaded into memory only when needed. As a result, the PRELOAD and LOADONCALL code attributes

【C++】关键字explicit的作用

泄露秘密 提交于 2019-12-06 20:34:07
简单的讲,关键字explicit可以禁止单参构造函数被用于自动类型转换。 看个单参构造函数用于自动类型转换的例子: #include <iostream> using namespace std; class Stack { public: Stack(int size) { m_size = size; }; int getSize() { return m_size; } private: int m_size; }; int main() { Stack stk(5); std::cout << stk.getSize() << std::endl; stk = 10; // 发生自动类型转换:10通过构造函数隐式建立一个对象 std::cout << stk.getSize() << std::endl; return 0; } 如果想禁止该类型转换(要求类的使用者必须显示调用类的构造函数),使用explicit关键字修饰构造函数即可: explicit Stack(int size) { m_size = size; }; 如此修饰后,上面的程序在编译时会给出错误提示。 我们设计类的时候参考的一个原则是:易于正确使用,难以错误使用。 2011-12-11 任洪彩 qdurenhongcai@163.com 转载请注明出处。 来源: oschina 链接: https:/

Explicit copy constructor and std::sort

拥有回忆 提交于 2019-12-06 18:51:50
问题 When sorting a container of objects having an explicit copy ctor I get compiler errors (from g++ 4.8.2 and clang++ 3.4, both in -std=c++11 mode) that I don't understand. I've created a simple example to demonstrate the problem class A { public: explicit A(int i): m_i(i) {}; explicit A(const A& other): m_i(other.m_i) {}; int i() const {return m_i;}; private: int m_i; }; bool is_less(const A& a, const A& b) { return a.i() < b.i(); } int main(int, char*[]) { std::vector<A> objects; objects.push