|
C++ Microsoft Visual Studio 2008
|
|
|
|
|
|
1 C++ ( 2) |
|
|
|
|
|
C++ MSVS 2008
Microsoft Visual Studio 2005 2008
( ) |
|
|
|
|
|
[]
[] [ ] |
|
|
|
|
|
C++ Microsoft
Visual Studio 2008 |
|
|
|
|
|
.
C++ . |
|
|
|
|
|
-
;
-
; |
|
|
|
|
|
-
;
(declaration) ,
. (definitions)
. , !
//
Declare and define int variables i and j.
int i;
int j = 10;
//
Declare enumeration suits.
enum suits { Spades = 1, Clubs, Hearts, Diamonds };
//
Declare class CheckBox.
class CheckBox : public Control
{
public:
Boolean IsChecked();
virtual int ChangeState() = 0;
}; |
|
|
|
|
|
(declaration) .
. (classes),
(structures), (enumerated types)
.
.
(definitions) :
-
( ());
-
extern, ( )
(). ,
;
-
;
,
,
.
-
;
-
typedef;
,
extern
int i;
char *strchr( const char *Str, const char Target ); |
|
|
|
|
|
(definitions)
() ,
, (enumerator).
,
. |
|
|
|
|
|
.
:
-
,
;
-
, .
.
:
//
definitions.cpp
class WindowCounter; // Forward reference; no definition
class
Window
{
// Definition of WindowCounter not required
static WindowCounter windowCounter;
};
int
main()
{
} |
|
|
|
|
|
MSVS 2008 -
- MSVS 2008 Documentation (
Help) - Development Tools and Languages > Visual Studio > Visual
C++ > Reference > C/C++ Languages > C++ Language Reference >
Statements > Declaration Statements |
|
|
|
|
|
-
;
Help - Development Tools and
Languages > Visual Studio > Visual C++ > Reference > C/C++
Languages > C++ Language Reference > Statements > Exception Handling
, .
, ,
, (Access Violation) .
.
try, catch throw |
|
|
|
|
|
try
{
// code that could throw an exception
}
[ catch (exception-declaration) {
// code that executes when exception-declaration is thrown
// in the try block
}
[catch (exception-declaration) {
// code that handles another exception type
} ] . . . ]
// The following syntax shows a throw expression:
throw [expression] |
|
|
|
|
|
C++ ,
(exceptions),
. try, throw
catch .
C++
,
.
.
try, catch, throw
try .
(throw expression) (raises exception).
catch ()
.
(exception-declaration)
catch. ,
C++.
(...), catch ,
C ,
, , .
try.
throw return.
:
1.
try .
try .
2.
,
catch, try .
catch try (thrown) .
3.
(thrown)
(
),
throw. ( , ).
catch
,
(thrown) ( catch,
). catch
try.
try - . ,
try - .
4.
, ,
terminate.
throw, ,
terminate.
5.
catch , ,
.
,
.
. ,
( ), try
catch (throw) .
. catch
(..
catch). catch
(thrown) goto
case switch.
|
|
|
|
|
|
MSVS try
catch.
new. new catch :
//
exceptions_trycatchandthrowstatements.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
int main() {
char *buf;
try {
buf = new char[512];
if( buf == 0 )
throw "Memory allocation failure!";
}
catch( char * str ) {
cout << "Exception raised: " << str << '\n';
}
} |
|
|
|
|
|
Win32- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[]
[] [ ] |
|