11. .
: , , , . , , .
Exception . Exception, ApplicationException SystemException. .
, Exception, Exception. , InvalidCastException :
Object SystemException InvalidCastException
SystemException . , ( ), . , , Exception. SystemException SystemException .
( ) ExecutionEngineException,StackOverflowException OutOfMemoryException.
SystemException ExternalException. , COMException , COM-, ExternalException. Win32Exception SEHException ExternalException.
, SystemException, . , , , .
. | ( , ). | ||
SystemException | , . | ( , ). | |
IndexOutOfRangeException | SystemException | . | : arr[arr.Length+1] |
NullReferenceException | SystemException | . | object o = null; o.ToString(); |
AccessViolationException | SystemException | . | , . |
InvalidOperationException | SystemException | . | Enumerator.GetNext() Item . |
ArgumentException | SystemException | . | ( , ). |
ArgumentNullException | ArgumentException | , . | String s = null; "Calculate".IndexOf (s); |
ArgumentOutOfRangeException | ArgumentException | , . | String s = "string"; s.Chars[9]; |
ExternalException | SystemException | , . | ( , ). |
ComException | ExternalException | , HRESULT COM. | COM. |
SEHException | ExternalException | , Win32. | . |
12. .
|
|
́ (. template) C++, , (, , , ).
C++ .
. ( , enum, ). , - :
class SomeClass{
int SomeValue;
int SomeArray[20];
...
}
. , , , . 30 SomeArray SomeValue SomeArray. . : template . :
template < int ArrayLength, typename SomeValueType > class SomeClass{
SomeValueType SomeValue;
SomeValueType SomeArray[ ArrayLength ];
...
}
:
SomeClass < 20, int > SomeVariable;
:
SomeClass < 30, double > SomeVariable2;
, , .
template, . :
template< typename T >
void sort(T array[], int size); // : sort ,
template< typename T >
void sort(T array[], int size) //
{
T t;
for (int i = 0; i < size - 1; i++)
|
|
for (int j = size - 1; j > i; j--)
if (array[j] < array[j-1])
{
t = array[j];
array[j] = array[j-1];
array[j-1] = t;
}
}
template< int BufferSize > //
char* read()
{
char *Buffer = new char[ BufferSize ];
/* */
return Buffer;
}
typename , [1] class typename:
template< class T >
T .
13. .
, . , , :
// .
template <class > ( , b) {
return > b? : b;
// . template <class > ( rr[], size_t size)
(
maxVal = arr[0];
for(int i=l; i<size; i++) if (arr[i] > maxVal) maxVal = arr[i];
return maxVal;
}
, , . . , .
, , () -, ( ). (char*, char*), , . (char*, char*):
char *Max(char *a, char *b) {
return strcmp(a, b) > 0? : b;
}
- , :
.
, , .
, .
14. .
. . :
template <__> _
, . , , . , .
, .
__ <__>
_ (_);
15. .
16. STL. . . .
STL : , , - .
vector | C- / . . - vector , vector . . . vector bool, , . |
list | , , vector, . , - . . . |
deque | . vector, . . , vector, , . |
set | . / , , . , , . operator< -. . |
multiset | set, . |
map | , . . . operator<, -. |
multimap | map, . |
- | |
stack | , . |
queue | , , . |
priority_queue | , , . |
bitset | . vector<bool> . , bitset. bitset . . |
basic_string | , . , . POD'. +. |
valarray | . vector, . valarray valarray (). , SIMD. |
. , . , . , . :
|
|
, | ||
operator== | operator== |
|
|
STL , . , , . C++ , :
operator++, operator*, operator->, , operator=, operator==, operator!= | . | |
operator++, operator*, | . . | |
operator++, operator*, operator->, , , operator=, operator==, operator!= | . . . | |
operator++, operator--, operator*, operator->, , , operator=, operator==, operator!= | , (. ). , . | |
operator++, operator--, operator*, operator->, , , operator=, operator==, operator!=, operator+, operator-, operator+=, operator-=, operator<, operator>, operator<=, operator>=, operator[] | : , . |
17. . , .