.
| | ( class T)
| |||
|---|---|---|---|---|
not a
|
bool T::operator!() const;
|
bool operator!(const T &a);
| ||
a and b
|
bool T::operator&&(const T2 &b) const;
|
bool operator&&(const T &a, const T2 &b);
| ||
a or b
|
bool T::operator||(const T2 &b) const;
|
bool operator||(const T &a, const T2 &b);
| ||
|
| ||||
! rhs
|
(1) | ||||||||
lhs && rhs
|
(2) | ||||||||
lhs || rhs
|
(3) | ||||||||
bool, bool bool: , bool t() t.
bool prvalue.
true, false. false.
true, ( ) true. : true, .
a
|
true
|
false
|
|---|---|---|
!a
|
false
|
true
|
and
|
a
| ||
|---|---|---|---|
true
|
false
| ||
b
|
true
|
true
|
false
|
false
|
false
|
false
| |
or
|
a
| ||
|---|---|---|---|
true
|
false
| ||
b
|
true
|
true
|
true
|
false
|
true
|
false
| |
bool operator!(bool) |
||
bool operator&&(bool, bool) |
||
bool operator||(bool, bool) |
||
#include <iostream>
#include <string>
int main()
{
int n = 2;
int* p = &n;
// bool
if( p && *p == 2 // "*p" "p &&"
|| !p && n != 2 ) // || , &&
std::cout << "true\n";
// bool
std::cout << " '' .\n";
for(std::string line; std::cout << "> "
&& std::getline(std::cin, line)
&& line != ""; )
;
}
:
true
'' .
>
>
operator&& operator|| , , :
| valarray (public - std::valarray)
| |
| valarray, valarray ( ) | |
| , ( fail()) (public - std::basic_ios)
|
|
|
|
|
|
|
|
|
a(...)
| ||||||
a, b
| ||||||
a ? b : c
| ||||||
|
static_cast | ||||||