assignment-operator

Default assignment operator in inner class with reference members

核能气质少年 提交于 2019-12-04 05:10:11
I've run into an issue I don't understand and I was hoping someone here might provide some insight. The simplified code is as follows (original code was a custom queue/queue-iterator implementation): class B { public: B() {}; class C { public: int get(); C(B&b) : b(b){}; private: B& b; }; public: C get_c() { return C(*this); } }; int main() { B b; B::C c = b.get_c(); c = b.get_c(); return EXIT_SUCCESS; } This, when compiled, gives me the following error: foo.cpp: In member function 'B::C& B::C::operator=(const B::C&)': foo.cpp:46: error: non-static reference member 'B& B::C::b', can't use

C: transitive (double) assignments

对着背影说爱祢 提交于 2019-12-04 04:40:20
问题 I have used such construct in C: list->head = list->tail = NULL; and now I consider whether this really mean what I suppose. Is this mean? list->head = NULL; list->tail = NULL; or list->head = list->tail; list->tail = NULL; thx for clarifying 回答1: Neither of those is correct. Since the simple assignment = operator is right-to-left associative, your expression is identical to: list->head = (list->tail = NULL); NULL is assigned to tail, and then tail, which has the value of a null pointer, to

derived class's virtual assignment operator not being called

只谈情不闲聊 提交于 2019-12-04 04:02:15
问题 I'm pretty new to C++, and am trying to come to grips with virtual assignment. The program below consists of an abstract base class with two data members, and a derived class with one. When I set an abstract pointer to a derived object, the program uses the abstract version of operator= rather than the derived version, even though they're both declared "virtual." What am I doing wrong here? Thanks in advance, Jay #include <iostream> #include <cstring> class Abstract { protected: char * label;

Why can't I assign an arbitrary iterable to an extended slice whose step is -1?

ぐ巨炮叔叔 提交于 2019-12-04 01:24:46
问题 Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> u = [4, 5, 6, 7, 8, 9] >>> u[1::1] = [3, 2, 1, 0] >>> u [4, 3, 2, 1, 0] >>> u[9:0:-1] = [8, 7, 6, 5] >>> u [4, 5, 6, 7, 8] >>> u[9:0:-1] = [16, 12, 8] Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: attempt to assign sequence of size 3 to extended slice of size 4 >>> u [4, 5, 6, 7, 8] >>> Expected

how to use if else in xquery assignment

强颜欢笑 提交于 2019-12-04 00:51:54
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> </libx:module>' This code throws an [XPST0003] Incomplete 'if' expression error. Can someone help me fix

Should I use lvalue reference qualifiers for assignment operators?

别说谁变了你拦得住时间么 提交于 2019-12-04 00:14:57
Recently, I have followed a discussion about assignments to expressions in C++ as shown in the following example: string s1, s2, s3; (s1 + s2) = s3; With C++11 it is possible to restrict the assignment operator to lvalue references (on the left side). When declaring the assignment operators as follow, the compiler Clang rejects the code with an error message due to incompatible types. auto operator=(const string& rhs) & -> string&; auto operator=(string&& rhs) & -> string&; I haven't seen this anywhere. Is there a good reason for not using lvalue reference qualifiers for assignment operators

Why doesn't a derived class use the base class operator= (assignment operator)?

本秂侑毒 提交于 2019-12-03 23:52:00
Following is a simplified version of an actual problem. Rather than call Base::operator=(int) , the code appears to generate a temporary Derived object and copy that instead. Why doesn't the base assignment operator get used, since the function signature seems to match perfectly? This simplified example doesn't display any ill effects, but the original code has a side-effect in the destructor that causes all kinds of havoc. #include <iostream> using namespace std; class Base { public: Base() { cout << "Base()\n"; } Base(int) { cout << "Base(int)\n"; } ~Base() { cout << "~Base()\n"; } Base&

Parsing “->” assignment operator in R

做~自己de王妃 提交于 2019-12-03 23:41:16
问题 My question is about parsing expressions in R language. Let me jump right into an example: fun_text <- c(" 0 -> var f1 <- function() { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 } (function() { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 })->f2 f3 = function(x) { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 } ") fun_tree <- parse(text=fun_text) fun_tree fun_tree[[1]] fun_tree[[2]] fun_tree[[3]] fun_tree[[4]] After that, we obtain those results: expression(0 -> var, f1 <- function() { 0 -> sum_var sum

Assignment operator and copy constructor in the presence of references

若如初见. 提交于 2019-12-03 18:05:51
问题 I am just experimenting with the references using this code: class A { }; class B { public: B(A& a): m_a(a){} A& m_a; }; int main() { A a; B b(a); B b1 = b; } I was expecting both B b1 = b; to produce a error. Instead when I compile with VS2008 I just get a warning warning C4512: 'B' : assignment operator could not be generated I understand why I am getting this warning. But shouldn't the compiler generating an error for the B b1 = b; statement too? It is like it generated copy constructor

Constructor or Assignment Operator

梦想与她 提交于 2019-12-03 15:14:07
Can you help me is there definition in C++ standard that describes which one will be called constructor or assignment operator in this case: #include <iostream> using namespace std; class CTest { public: CTest() : m_nTest(0) { cout << "Default constructor" << endl; } CTest(int a) : m_nTest(a) { cout << "Int constructor" << endl; } CTest(const CTest& obj) { m_nTest = obj.m_nTest; cout << "Copy constructor" << endl; } CTest& operator=(int rhs) { m_nTest = rhs; cout << "Assignment" << endl; return *this; } protected: int m_nTest; }; int _tmain(int argc, _TCHAR* argv[]) { CTest b = 5; return 0; }