Linked Questions

289 votes
6 answers
512k views

I am writing a small matrix library in C++ for matrix operations. However, my compiler complains, where before it did not. This code was left on a shelf for six months and in between I upgraded my ...
Matthias van der Vlies's user avatar
109 votes
6 answers
141k views

a.h #include "logic.h" ... class A { friend ostream& operator<<(ostream&, A&); ... }; logic.cpp #include "a.h" ... ostream& logic::operator<<(ostream& os, A& a) {...
As As's user avatar
  • 2,107
116 votes
5 answers
101k views

How can I overload the operator++ in two different ways for postfix a++ and prefix ++a?
rookie's user avatar
  • 7,913
90 votes
8 answers
60k views

In C++, the concept of returning reference from the copy assignment operator is unclear to me. Why can't the copy assignment operator return a copy of the new object? In addition, if I have class A, ...
bks's user avatar
  • 1,896
52 votes
13 answers
11k views

I have implemented operator< for a certain object. Logically, if !(a < b) and !(b < a) it means a == b. Is this inferred automatically? Can I use == if I only implement <?
Eyzuky's user avatar
  • 1,955
150 votes
2 answers
121k views

I read that an overloaded operator declared as member function is asymmetric because it can have only one parameter and the other parameter passed automatically is the this pointer. So no standard ...
badmaash's user avatar
  • 4,865
64 votes
7 answers
37k views

How to define operator< on n-tuple (for example on 3-tuple) so that it satisfy strict weak ordering concept ? I know that boost library has tuple class with correctly defined operator< but for ...
Konstantin's user avatar
  • 6,161
89 votes
2 answers
80k views

I'm implementing vector class and I need to get an opposite of some vector. Is it possible to define this method using operator overloading? Here's what I mean: Vector2f vector1 = -vector2; Here's ...
Ilya Suzdalnitski's user avatar
60 votes
4 answers
81k views

Can we overload operator++ for pre-increment and post-increment? i.e. calling SampleObject++ and ++SampleObject gives the correct results. class CSample { public: int m_iValue; // just to ...
null's user avatar
  • 807
54 votes
5 answers
66k views

I have a question about the return value of operator overloading in C++. Generally, I found two cases, one is return-by-value, and one is return-by-reference. So what's the underneath rule of that? ...
skydoor's user avatar
  • 26k
79 votes
3 answers
109k views

There are two ways to overload operators for a C++ class: Inside class class Vector2 { public: float x, y ; Vector2 operator+( const Vector2 & other ) { Vector2 ans ; ...
bobobobo's user avatar
  • 67.9k
54 votes
4 answers
73k views

So, after researching everywhere for it, I cannot seem to find how to create a class arrow operator, i.e., class Someclass { operator-> () /* ? */ { } }; I just need to know how to work ...
Codesmith's user avatar
  • 6,929
41 votes
5 answers
19k views

I have to overload a == operator in C++ for a class with many attributes. The operator should return true, if and only if all attributes are equal. A shortcut might be useful, if these attributes ...
Mehno's user avatar
  • 918
44 votes
5 answers
86k views

Which is best practice (in this case): bool Foo::operator==(const Foo& other) { return bar == other.bar; } // Implementation 1 bool Foo::operator!=(const Foo& other) { return bar != ...
blaze's user avatar
  • 2,674
58 votes
2 answers
9k views

Say I am working with a class: class Foo{ public: std:string name; /*...*/ }/*end Foo*/ and I provide an overload for operator== bool operator==(const Foo& fooObj, const std::string& ...
hehe3301's user avatar
  • 766

15 30 50 per page
1
2 3 4 5
93