» Home » Operator » Page 1
Operator overloading “operator T * ()” produces a comparison operator?
Category : Programming Languages
class Test
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

View Replies

Are there FP names for operator that pipes an operation into innermost structure ? (similar to the |> operator in fsharp)
Category : 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

View Replies

C++ Beginner - 'friend' functions and << operator overloading: What is the proper way to overload an operator for a class?
Category : 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.

View Replies

proper usage of the pre-increment operator in combination with the pointer dereference operator
Category : 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

View Replies

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

View Replies

Operator overloading in python with the object on the right hand side of the operator
Category : 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

View Replies

Can I replace the binding operator with the smart match operator in Perl?
Category : 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;

View Replies

C++ operator overloading affect in-class operator functions
Category : 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

View Replies

'operator new': redefinition, different linkage (using _dllspec on redefined new operator)
Category : Programming Languages

I am using __declspec(dllimport/export) on a debug version of new as such:

#ifdef _DEBUG
DECLSPECCORE extern void* operator new(unsigned int size, const char* file, int line);
extern void* operator new[](unsigned int size, const char* file, int line);
extern void operator delete(void* address, const char* file, int line);
extern void operator delete[](vo

View Replies

How to call a templated operator overload without using the word 'operator'?
Category : 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

View Replies

2012 / 2017 Copyrights BigHow , All Rights Reserved .