Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ unary minus overload

class A{
public:
	A operator-() const{
    	A temp;
    	temp.someData = -std::abs(temp.someData);
      	return temp;
    } // Or you can make a friend operator
  	friend A operator-(A un){ // You can use a reference instead but then
    	un.someData = -std::abs(un.someData);     // you have to create a
      	return un;                                // temporary object.
    }                                             // Not a big difference
private:
	int someData;
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: convert whole string to uppercase c++ 
Cpp :: taking user input for a vector in c++ 
Cpp :: c++ randomization 
Cpp :: eosio name to string 
Cpp :: sort in descending order c++ stl 
Cpp :: how to remove spaces from a string 
Cpp :: qstring insert character 
Cpp :: qt qstring to double 
Cpp :: c++ absolute value 
Cpp :: c++ std::copy to cout 
Cpp :: winmain example 
Cpp :: binary exponentiation modulo m 
Cpp :: point is on line 
Cpp :: how to make a hello world program in c++ 
Cpp :: fork was not declared in this scope 
Cpp :: c++ file exists 
Cpp :: mpi_bcast 
Cpp :: what is the difference between i++ and ++ i ? 
Cpp :: calling struct to a struct c++ 
Cpp :: delete last char of string c++ 
Cpp :: find last occurrence of character in string c++ 
Cpp :: c++ switch case break 
Cpp :: c++ type casting 
Cpp :: c++ random number 0 to 1 
Cpp :: c++ reading string 
Cpp :: vector fin element c++ 
Cpp :: c++ get environment variable 
Cpp :: Parenthesis Checker using stack in c++ 
Cpp :: on component begin overlap c++ 
Cpp :: size of stack in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =