assignment-operator

C++ Qt Reflection with Copy and Assignment

一曲冷凌霜 提交于 2019-12-23 09:05:28
问题 As the QObject documentation and many others explain, a QObject has an identity and thus hides its copy constructor and assignment operator. However, I'm not deriving from QObject for its dynamic properties feature or the signals/slots feature. I only want reflection , or the ability to access Foo::staticMetaObject . class Foo : public QObject { Q_OBJECT Q_ENUMS(Color) public: enum Color { Blue, Red, Pink }; private: Color color; }; Q_DECLARE_METATYPE(Foo::Color) I then can't copy Foo with:

Why doesn't RVO happen for assignment operator? (C++)

爷,独闯天下 提交于 2019-12-23 02:44:12
问题 Example: A myfunction() { return A(); } A a = myfunction(); // default ctor only (return value optimization) a = myfunction(); // default ctor and operator= Why can't the compiler just write the new object into the existing object? I believe all instances of a class occupy the same amount of (non dynamic) memory, so I don't see why this would be a problem. 回答1: RVO happens only because the C++ standard gives compilers a special license to ignore side effects in the copy constructor and the

Virtual assignment operator overloading- how the correct overloaded function is chosen?

送分小仙女□ 提交于 2019-12-22 17:49:05
问题 The following code (from C++ FAQs 24.11) is implementing virtual assignment operator overloading and overriding: #include <iostream> using namespace std; class B{ public: virtual ~B() throw(); virtual B& operator= (const B& b) throw(); }; B::~B() throw(){} B& B::operator= (const B& b) throw() { cout << "B::operator=(const B&)\n"; return *this; } class D : public B{ public: virtual D& operator= (const B& b) throw(); D& operator= (const D& d) throw(); }; D& D::operator= (const B& b) throw()

Operators precedence of “or” and assignment

大憨熊 提交于 2019-12-22 13:07:28
问题 Found some interesting code snippet today. Simplified, it looks like this: $var = null; $var or $var = '123'; $var or $var = '312'; var_dump($var); The thing is that, as i know, precedence of assignment is higher that OR, so, as i assume, var_dump should output 312 (first - assign, second - compare logically). But result is defferent, i getting 123 (first - check if $var converting to true , second - if not, assign value). The questions is how does it work? Why behavior is the same for or and

Simple substitute of assignment operators of logical ones in JavaScript?

喜你入骨 提交于 2019-12-22 11:22:11
问题 JavaScript has assignment operators corresponding to arithmetic ones: += , -= , *= , /= , %= . JavaScript also has assignment operators corresponding to bitwise ones: <<= , >>= , >>>= , &= , ^= , |= . But it doesn't have assignment operators corresponding to logical ones: ||= , &&= . Then, I can't do things like aVeryLongVariableIdontWantToRepeat ||= 1; In this other question it's explained why JS Java doesn't have such operators. I guess it's the same for JS. But I want to know if there is a

JavaScript evaluation order when assigning

此生再无相见时 提交于 2019-12-22 10:01:05
问题 At what point does JavaScript determine the left-hand side of an assignment — is it before or after the right-hand side is evaluated? For example, what does this code do? var arr = [{thing:1},{thing:2},{thing:3},{last:true}]; arr[arr.length - 1].newField = arr.pop(); 回答1: The left-hand side of an assignment operator is evaluated first. The specification for this as of ES2015 can be found in the "Runtime Semantics: Evaluation" portion of the "Assignment Operators" section and can be very

is_assignable and std::unique_ptr

橙三吉。 提交于 2019-12-22 05:36:18
问题 Here is a test file from gcc, live demo struct do_nothing { template <class T> void operator()(T*) {} }; int main() { int i = 0; std::unique_ptr<int, do_nothing> p1(&i); std::unique_ptr<int> p2; static_assert(!std::is_assignable<decltype(p2), decltype(p1)>::value, ""); // note ! here. } std::is_assignable If the expression std::declval<T>() = std::declval<U>() is well-formed in unevaluated context, provides the member constant value equal true. Otherwise, value is false. Access checks are

Default copy assignment with array members

久未见 提交于 2019-12-22 04:30:15
问题 I've got a class definition similar to the following: class UUID { public: // Using implicit copy assignment operator private: unsigned char buffer[16]; }; I've just had a unit test fail on me that was verifying that copy assignment worked properly. To my surprise, one byte in the middle of the buffer[] array was copied incorrectly. My understanding is that the default copy assignment operator performs memberwise copy, and that for array members (not pointer-to-array members) that entails

how to use if else in xquery assignment

江枫思渺然 提交于 2019-12-21 07:02:27
问题 I am trying to use a if condition to assign a value to a variable in an xquery. I am not sure how to do this. This is what I tried: declare namespace libx='http://libx.org/xml/libx2'; declare namespace atom='http://www.w3.org/2005/Atom'; declare variable $entry_type as xs:string external; let $libx_node := if ($entry_type = 'package' or 'libapp') then {element {fn:concat("libx:", $entry_type)} {()} } else if ($entry_type = 'module') then '<libx:module> <libx:body>{$module_body}</libx:body> <

Shorthand assignment operator for inverting boolean

前提是你 提交于 2019-12-20 07:15:00
问题 There are shorthand operators for the basic arithmetic operators, such as: x = x+2; x += 2; or y = y*2; y *= 2; However, I was wondering if there was any such operator that could simply invert the value of a boolean. For example, assuming z = true , is there any shorter equivalent to: z = !z; I know it can't be just !z , because then it would just return the opposite value of z , but it wouldn't change its value. I know I'm kind of lazy, but I use this a lot in my code and am trying to