operator-keyword

wrapper class for STL stream: forward operator<< calls

本小妞迷上赌 提交于 2019-12-13 18:51:22
问题 I'm currently writing a wrapper for STL stream to synchronize write calls from multiple threads. I have the following (simplified) code: class Synchronize { private: std::stringstream ss; public: void write(std::string& str) { // locking ... ss << str; // unlocking ... }; // other stuff .. }; Synchronize& operator<<(Synchronize& o, std::string& str) { o.write(str); return o; } Synchronize& operator<<(Synchronize* o, std::string& str) { o->write(str); return *o; } Its now possible to call the

R: Replace “+” character with gsub

别等时光非礼了梦想. 提交于 2019-12-13 13:26:50
问题 the question seems totally trivial but I cannot figure out why it isn't working. I simply want to replace a character variable involving a "+" operator with a single value excluding the "+" operator. For some reason gsub() and sub() function replace the number value but keep the operator. Any hint on how this can be overcome? Many thanks! data <- c(1,2,3,4,"5+") gsub(pattern="5+",replacement="5",x=data) #[1] "1" "2" "3" "4" "5+" gsub(pattern="5+",replacement="",x=data) #[1] "1" "2" "3" "4" "+

no instance of overloaded function

感情迁移 提交于 2019-12-13 08:59:23
问题 trying to do a project for class, but keep getting the error: no instance of overloaded function matches argument list relating to the implementation of the rows vector. the area that is specifically highlighted is the . operator before push_back and insert. void holdLines(ifstream in, vector<string> rows) { string line; string prevLine; vector<string> rows; int lineNumber = 0; int vectorNumber = 0; while(true) { getline(in, line); if(in.fail()) { break; } lineNumber++; vectorNumber =

Operator Associativity

自古美人都是妖i 提交于 2019-12-13 07:04:54
问题 I have the following EBNF expression grammar: <expr> -> <term> { (+|-) <term> } <term> -> <factor> { (*|/|%) <factor> } <factor> -> <pow> { ** <pow> } <pow> -> ( <expr> ) | <id> <id> -> A | B | C I need to determine if the grammar enforces any particular associativity for its operators, or if that would have to be implemented in the parser code. From what I have read so far, it doesn't look like it does, but I am having a hard time understanding what causes associativity. Any help would be

Solr AND operator not working

我的未来我决定 提交于 2019-12-13 06:19:55
问题 http://localhost:8080/products/select?indent=on&q=text:30MM X 533MM Abrasives&fl=*,[docid] returns docid 187095 http://localhost:8080/products/select?indent=on&q=textfields:30MM X 533MM Abrasives&fl=*,[docid] returns docid 187095 http://localhost:8080/products/select?indent=on&q=textfields:30MM X 533MM Abrasives AND text:30MM X 533MM Abrasives&fl=*,[docid] returns no result. Am I not applying AND correctly ? 回答1: If you use fielded data in your query and you don't use double quotes ("), the

python operator overload and friends

拜拜、爱过 提交于 2019-12-13 05:24:43
问题 I wanted to know if anyone could give me an example of how to overload an operator within a class, in my case the + operator. Could I define a function (not a class method) that does it? I'm a newbie so I don't really know how to do it. Thanks 回答1: class MyNum(object): def __init__(self, val): super(MyNum,self).__init__() self.val = val def __add__(self, num): return self.__class__.(self.val + num) def __str__(self): return self.__class__.__name__ + '(' + str(self.val) + ')' print(MyNum(3) +

How to use friend operators in a template class? [duplicate]

筅森魡賤 提交于 2019-12-13 04:37:24
问题 This question already has an answer here : Overloading << operator in C++ when using templates in linked list program (1 answer) Closed 5 years ago . I have template class which has some friend operators. The compiler complains about "friend declaration declares a non-template function". Unfortunately, I don't know how to resolve this error. Any hints? The code looks as follows: template<typename X> class Vect { protected: X v1_; X v2_; X v3_; public: Vect( X v1, X v2, X v3 ); Vect( const

c++ nested conditional operator loop

断了今生、忘了曾经 提交于 2019-12-13 04:37:19
问题 I'm curious about how c++ handles this nested conditional operator. I'm half sure that I understand how this works, but I'm curious, could anyone explain through a diagram how the loop would execute the nested conditional operator . For example would the loop execute through the first expression of each conditional operator for each instance? Also is this nested conditional operator structured as: (i < 2) ? x[i] : y; !i ? y : x[1]; I guess I'm just very curious about the nature of this.

Override = operator linked linked c++ deep copy

£可爱£侵袭症+ 提交于 2019-12-13 04:24:37
问题 So, I'm trying override operator= in a linked list class I'm writing, but keep getting this weird problem for some reason. List& List::operator=(const List& copyList){ if(copyList.head != nullptr){ makeEmpty(); // clears *this from any previous nodes cout << "if statement " << endl; head = new Node; // create a new node for head head -> data = copyList.head -> data; // copy the first data of copylist Node* pnew = head; // a temp node to traverse the new linkedlist assert(head != nullptr);

Overloading + to add two pointers

ぃ、小莉子 提交于 2019-12-13 03:57:19
问题 I have a String class and I want to overload + to add two String* pointers. something like this doesn't work: String* operator+(String* s1, String* s2); Is there any way to avoid passing by reference. Consider this example: String* s1 = new String("Hello"); String* s2 = new String("World"); String* s3 = s1 + s2; I need this kind of addition to work. Please suggest. 回答1: You can't. You cannot overload operators for built-in types. In any case, why use pointers at all? Avoid dynamic allocation