» Home » Operator » Page 1
Operator overloading “operator T * ()” produces a comparison operator?
by amiT jaiN in Programming Languages
class Test
{
public:
operator Test * () { return NULL; };
};
int main()
{
Test test;
if (test == NULL)
printf("Wtf happened here?
");
return 0;
}

How is it that this code compiles? How did Test get a comparison operator? Is there some implicit casting going around? What does that overload


C++ Beginner - 'friend' functions and << operator overloading: What is the proper way to overload an operator for a class?
by raven84 in Programming Languages

In a project I'm working on, I have a Score class, defined below in score.h. I am trying to overload it so, when a << operation is performed on it, _points + " " + _name is returned.


Here's what I tried to do:


ostream & Score::operator<< (ostream & os, Score right)
{
os << right.

Are there FP names for operator that pipes an operation into innermost structure ? (similar to the |> operator in fsharp)
by Pete in Programming Languages

I had to write 2 operators :


let inline (|/>) (seqinit:seq<'a*'T>) f = seqinit |> Seq.map (fun (key1 ,seq1) -> (key1, seq1 |> f ))
let inline (||>) (seqinit:seq<'a * seq<'b>>) (f2:seq<'b>->seq<'c*seq<'d>>) = seqinit |> Seq.map (fun (key1 ,seq1) -> (key1, seq1 |> f2 ))

In order to have the


proper usage of the pre-increment operator in combination with the pointer dereference operator
by Seba in Programming Languages

I just wrote the following line of code:


if (++(data_ptr->count) > threshold) { /*...*/ } // example 1

My intent is to increment the count variable within the data structure that data_ptr points to before making the comparison to threshold, and this line of code works.


If I had instead wanted to increme


I keep getting a error:“no operator >> matches thees operands” on variables that are int and bool. In the >> operator overload
by Brian in Programming Languages
class user
{
private:
std::string first_name;
std::string middle_name;
std::string last_name;
int ID;
static int next_id;
public:
static int next_user_id()
{
next_id++;
return next_id;
}
group User_Group;
void set_ID(int c)

Operator overloading in python with the object on the right hand side of the operator
by Remyx in Programming Languages

I recently learned about operator overloading in python and I would like to know if the following is possible.


Consider the folowing hypothetica/contrived class.


class My_Num(object):
def __init__(self, val):
self.val = val
def __add__(self, other_num):
if isinstance(other_num, My_Num):
return self.val + oth

Can I replace the binding operator with the smart match operator in Perl?
by cbrunny in Programming Languages

How can I write this with the smart match operator (~~)?


use 5.010;
my $string = '12 23 34 45 5464 46';
while ( $string =~ /(dd)s/g ) {
say $1;
}

How to call a templated operator overload without using the word 'operator'?
by Jimzz in Programming Languages
class RunAround;
class HopUpAndDown;
class Sleep;
template<typename Acts> int doThis();
template<> int doThis<RunAround>() { /* run run run.. */ return 3; }
template<> int doThis<HopUpAndDown>() { /* hop hop hop.. */ return 2; }
template<> int doThis<Sleep>() { /* zzz.. */ return -2; }
struct Results

Overloading GetHashCode and the equality operator using the XOR operator on enums
by Kbotei in Programming Languages

I have the following class which is part of a statictical analysis package.


The MetricKey object is used as a dictionary key.
Decision, MetricUnit & Portfolio are all enums.

I had to override the equality operator (==) to get dictionary key matching working. I used the guidance at http://msdn.microsoft.com/en-us/libra


C++ operator overloading affect in-class operator functions
by chuck1723 in Programming Languages

What if i overload the != operator and use class!= inside one of other operator overloaders, does it accept it as non-overloaded or overloaded? I am trying to create a noob_ptr (a kind of custom-pointer wraper i am thinking of)


class noob_ptr
{
private: //does this change the behaviour? public? protected?
bool operator!=(noob

Next
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2014 © bighow.org All Rights Reserved .