Hi, in TC++PL3 on page 665, regarding valarray member functions, it is
mentioned:
"valarray operator-() const; // result[i]= -v[i] for every element
// similarly: +, ~, !"
I checked the web and could not find anything that explains the need of
this "operator+".
Any ideas?
In MSDN it is mentioned:
"Standard C++ Library Reference
valarray::operator+
A unary operator that applies a plus to each element in a valarray.
valarray<Typeoperator+( ) const;
Return Value
A valarray whose elements are plus those of the operand array.
Example
// valarray_op_eplus.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<intvaL ( 10 );
valarray<intvaPLUS ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
vaL [ i ] = -i;
for ( i = 1 ; i < 10 ; i += 2 )
vaL [ i ] = i-1;
cout << "The initial valarray is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
vaPLUS = +vaL;
cout << "The element-by-element result of "
<< "the operator+ is the\n valarray: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaPLUS [ i ] << " ";
cout << ")." << endl;
}
Output
The initial valarray is: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
The element-by-element result of the operator+ is the
valarray: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
Requirements
Header: <valarray>" 2 1929
john wrote:
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is
mentioned:
"valarray operator-() const; // result[i]= -v[i] for every element
// similarly: +, ~, !"
I checked the web and could not find anything that explains the need
of this "operator+".
Any ideas?
In MSDN it is mentioned:
"Standard C++ Library Reference
valarray::operator+
A unary operator that applies a plus to each element in a valarray.
valarray<Typeoperator+( ) const;
Return Value
A valarray whose elements are plus those of the operand array.
Example
// valarray_op_eplus.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<intvaL ( 10 );
valarray<intvaPLUS ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
vaL [ i ] = -i;
for ( i = 1 ; i < 10 ; i += 2 )
vaL [ i ] = i-1;
cout << "The initial valarray is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
vaPLUS = +vaL;
cout << "The element-by-element result of "
<< "the operator+ is the\n valarray: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaPLUS [ i ] << " ";
cout << ")." << endl;
}
Output
The initial valarray is: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
The element-by-element result of the operator+ is the
valarray: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
You're talking about the uniary + operator. The unary minus operator does
indeed make sense, returning the negative of a number or value, but, yes,
what sense does a unary + operator make since it would just return the
value? In most cases, it would indeed only return the value although you
could overload it to do anything you want (such as return the abs of the
value).
I think it's main purpose is for completeness, since someone can indeed do:
x = +y;
--
Jim Langston ta*******@rocketmail.com
On Dec 15, 4:13 pm, john <j...@no.spamwrote:
Hi, in TC++PL3 on page 665, regarding valarray member
functions, it is mentioned:
"valarray operator-() const; // result[i]= -v[i] for every element
// similarly: +, ~, !"
I checked the web and could not find anything that explains
the need of this "operator+".
Any ideas?
What is the use of unary + on an int or a double? Logical (and
mathematical) coherence.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pmb |
last post by:
I've been working on creating a Complex class for my own learning purpose
(learn through doing etc.). I'm once again puzzled about something. I can't
figure out how to overload the assignment...
|
by: fourfires.d |
last post by:
Dear All,
I am new to c++ and when write below code that try to call copy
constructor
in "=" operator overloading, it can not compile. Can anyone point out
for
me the reason? thanks !!
...
|
by: ano |
last post by:
Hi,
I have converted this VB code to C# but I got this error:
"Operator '||' cannot be applied to operands of type 'int' and 'short'"
Is VB allow to use Operator "Or" with 'int'?
If yes, how...
|
by: ano |
last post by:
Hi all,
I try to convert VB codes to C#. I got this error "Operator '!'cannot be
applied to operand of type 'long'".
Any ideas? Why doesn't "Not SYNCHRONIZE" equivalent to "!SYNCHRONIZE"?
...
|
by: av |
last post by:
i have my little string class, now i want do define something like
this
but for doing it i have to write
sstream& operator+(char* a, char* b){}
but compiler say something like...
|
by: John Goche |
last post by:
Hello,
Could anyone please provide with some information on the
C++ overloaded cast operator and in which circumstances
this might be useful? I have consulted several references
but found no...
|
by: Sunny |
last post by:
The way to overload operator << is : ostream& operator << (ostream&
os, const Obj& obj);
and this is a member function.
My question is why do we need to provide a const reference of Obj as...
|
by: Luna Moon |
last post by:
Hi all,
I just couldn't get myself clear about the usage of "const" in front
of and/or behind variables, pointers, classes, objects and
functions...
It's too confusing... any good clear...
|
by: Bill Davy |
last post by:
I want to be able to write (const char*)v where v is an item of type
Class::ToolTypeT where ToolTypeT is an enumeration and I've tried
everything that looks sensible. There's an ugly solution, but...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |