No matching function for to call operator ++ overloading
The postfix increment is supposed to increment this
and return the value before the increment. You get the error because there is no constructor for person
taking an int
. You can fix that by:
person operator++(int)
{
person temp{name,age};
age++;
return temp;
}
Though better would be to provide a copy constructor and typically postfix increment can be implemented in terms of prefix increment:
// prefix
person& operator++() {
age++;
return *this;
}
// postfix
person operator++(int) {
person temp = *this; // needs copy constructor
++*this;
return temp;
}
For more details on operator overloading I refer you to What are the basic rules and idioms for operator overloading?
Operator on template argument type member causes error only in clang
std::tuple<std::string, std::string>
Let's look at the associated namespaces of this type. [basic.lookup.argdep]/(2.2):
Its associated namespaces are the
innermost enclosing namespaces of its associated classes.
That would be namespace std
or auxiliary ones, but certainly not the global namespace.
Furthermore, if
T
is a class template specialization, its associated
namespaces and classes also include: the namespaces and classes
associated with the types of the template arguments provided for
template type parameters (excluding template template parameters); [… inapplicable rules…]
Recursively applying the above to std::string
gives namespace std
(and, again, auxiliary ones) for the associated namespaces. Certainly not the global namespace. Clearly, the same argumentation can be repeated for std::cout
, giving the same conclusion.
Thus ADL won't look in the global namespace, which is precisely where your overload is declared in.
Finally, as per [temp.dep.candidate]/1, name resolution is unsuccessful:
GCC behaves non-conforming here; see #51577.
What is operator called?
<<
left shift
>>
right shift
No matching function for call to operator new
To use the standard placement form of new
you have to #include <new>
.
The form of new
that you are using requires a declaration of void* operator new(std::size_t, void*) throw();
.
You don't have to #include <new>
to use non-placement new
.
What is the name of the :: operator?
::
is the scope resolution operator (you may sometimes find references to Paamayim Nekudotayim
, hebrew for "double colon"). It is used to call static functions of a class, as in
class MyClass {
public static function hi() {
echo "hello, world";
}
}
MyClass::hi();
For more details on classes and objects, refer to the official documentation.
What is the official name of C++'s arrow (-) operator?
The C++ standard just calls it "arrow" (§5.2.5).
Related Topics
G++' Is Not Recognized as an Internal or External Command, Operable Program or Batch File
How Can Adding Code to a Loop Make It Faster
Is There a Gcc Preprocessor Directive to Check If the Code Is Being Compiled on a 64 Bit MAChine
What Is the Meaning of Double Curly Braces Initializing a C-Struct
Can You Start a Class Name with a Numeric Digit
Calling Delete on Null Pointers - C++03 VS C++11
Reading a Matrix Txt File and Storing as an Array
Direct C Function Call Using Gcc's Inline Assembly
Or Is Not Valid C++:Why Does This Code Compile
Why Can't Std::Function Bind to C-Style Variadic Functions
Stl Ordering - Strict Weak Ordering
Partial Specialization Ordering with Non-Deduced Context
Sub-Millisecond Precision Timing in C or C++
How to Determine If Returned Pointer Is on the Stack or Heap