overloading

Better way to call overloaded functions with more-derived parameters, passing in less-derived types

不问归期 提交于 2021-02-17 05:13:40
问题 I have 16 methods that take two parameters, and each of the two parameters can be either an 'Insertion' or a 'Deletion', both of which implement IFragment. I also have four helper functions like this: static IFragment[] IntroduceAntecedent(IFragment on, IFragment item) { bool onIsInsertion = on is Insertion; bool itemIsInsertion = item is Insertion; if (onIsInsertion) { if (itemIsInsertion) { return IntroduceAntecedent((Insertion) on, (Insertion) item); } else { return IntroduceAntecedent(

Better way to call overloaded functions with more-derived parameters, passing in less-derived types

一曲冷凌霜 提交于 2021-02-17 05:12:50
问题 I have 16 methods that take two parameters, and each of the two parameters can be either an 'Insertion' or a 'Deletion', both of which implement IFragment. I also have four helper functions like this: static IFragment[] IntroduceAntecedent(IFragment on, IFragment item) { bool onIsInsertion = on is Insertion; bool itemIsInsertion = item is Insertion; if (onIsInsertion) { if (itemIsInsertion) { return IntroduceAntecedent((Insertion) on, (Insertion) item); } else { return IntroduceAntecedent(

How to resolve ambiguity of call to overloaded function with literal 0 and pointer

℡╲_俬逩灬. 提交于 2021-02-16 10:00:28
问题 I'm pretty sure this must have been here already, but I didn't find much information on how to solve this kind of problem (without casting on the call): Given two overloads, I want that a call with function with a literal 0 always calls the unsigned int version: void func( unsigned int ) { cout << "unsigned int" << endl; } void func( void * ) { cout << "void *" << endl; } func( 0 ); // error: ambiguous call I understand why this happens, but I don't want to write func( 0u ) or even func(

How to resolve ambiguity of call to overloaded function with literal 0 and pointer

纵饮孤独 提交于 2021-02-16 09:59:56
问题 I'm pretty sure this must have been here already, but I didn't find much information on how to solve this kind of problem (without casting on the call): Given two overloads, I want that a call with function with a literal 0 always calls the unsigned int version: void func( unsigned int ) { cout << "unsigned int" << endl; } void func( void * ) { cout << "void *" << endl; } func( 0 ); // error: ambiguous call I understand why this happens, but I don't want to write func( 0u ) or even func(

So, basically my code is printing None after printing the statement I want it to print. How can I stop this None from printing

北战南征 提交于 2021-02-11 12:35:00
问题 So, basically my code is printing None after printing the statement I want it to print. How can I stop this None from printing class Panda: def __init__(self,name,gender,age): self.name=name self.gender=gender self.age=age def sleep(self,time=None): self.time=time if self.time!=None: if self.time>=3 and self.time<=5: self.food='Mixed Veggies' if self.time>=6 and self.time<=8: self.food='Eggplant & Tofu' if self.time>=9 and self.time<=11: self.food='Broccoli Chicken' print('{} sleeps {} hours

So, basically my code is printing None after printing the statement I want it to print. How can I stop this None from printing

ぃ、小莉子 提交于 2021-02-11 12:34:11
问题 So, basically my code is printing None after printing the statement I want it to print. How can I stop this None from printing class Panda: def __init__(self,name,gender,age): self.name=name self.gender=gender self.age=age def sleep(self,time=None): self.time=time if self.time!=None: if self.time>=3 and self.time<=5: self.food='Mixed Veggies' if self.time>=6 and self.time<=8: self.food='Eggplant & Tofu' if self.time>=9 and self.time<=11: self.food='Broccoli Chicken' print('{} sleeps {} hours

Error with abs() in c++

爱⌒轻易说出口 提交于 2021-02-11 11:51:10
问题 Getting error with abs() function at line 35 in this code. Compiler I choosed : c++(4.3.2) Look error at bottom. void bfs(pair<int,int> pixelpos){ bfsq.push(pixelpos); int u,v,i,j; pair<int,int> tmpq; while(!bfsq.empty()){ tmpq = bfsq.front(); u = tmpq.first; v = tmpq.second; bfsq.pop(); r(i,u-square_dist,u+square_dist) r(j,v-square_dist,v+square_dist) if(inrange(i,j)){ // ERROR HERE DOWN IN abs() fn int dist = abs(pixelpos.first - i) + abs(pixelpos.second -j); // Line: 35 if(graph[i][j]>dist

Error with abs() in c++

梦想与她 提交于 2021-02-11 11:50:46
问题 Getting error with abs() function at line 35 in this code. Compiler I choosed : c++(4.3.2) Look error at bottom. void bfs(pair<int,int> pixelpos){ bfsq.push(pixelpos); int u,v,i,j; pair<int,int> tmpq; while(!bfsq.empty()){ tmpq = bfsq.front(); u = tmpq.first; v = tmpq.second; bfsq.pop(); r(i,u-square_dist,u+square_dist) r(j,v-square_dist,v+square_dist) if(inrange(i,j)){ // ERROR HERE DOWN IN abs() fn int dist = abs(pixelpos.first - i) + abs(pixelpos.second -j); // Line: 35 if(graph[i][j]>dist

c++ friend overloading operator <<

大憨熊 提交于 2021-02-10 14:19:44
问题 I am trying overload the operator << but i keep having this error. I try doing research but with no result. I have a Point2D.h and a Point2D.cpp with a friend functions to overload. Below are my codes: Point2D.h #include <string> #include <iomanip> using namespace std; #ifndef Point2D_H #define Point2D_H class Point2D { friend ostream& operator<< (ostream&, Point2D); public: Point2D(); Point2D(int, int); protected: int x; int y; }; Point.cpp #include <string> #include <cmath> #include

invalid operands of types - c++

青春壹個敷衍的年華 提交于 2021-02-10 07:57:27
问题 I have a class named ThreeDigits on c++ code. I overloaded the + operand, this way: ThreeDigits* ThreeDigits::operator+(const ThreeDigits &number) const { double result= getNumber()+number.getNumber(); ThreeDigits* new_result=new ThreeDigits(result); return new_result; } but when I write on the main function: ThreeDigits* first=new ThreeDigits(2.55998); ThreeDigits* second=new ThreeDigits(5.666542); ThreeDigits* result=first+second; I get the following compilation error: invalid operands of