问题:关于C++ 关键字详细解释
auto break case chat class const
continue default delete do double else
enum explicit extern float for fiend
goto if inline int long mutable
new operator privatc protected public register
retum short signed sizeof static static_cast
struct switch this typedef union unsigned
virtual viod while
----------------------------------------------------------------------------
我希望斑竹能详细解答
本人现在自学C++,大家一起学习。。
我觉得这个区能引导大家去学好语言才算是语言专业区
偶知道会很大工程,不过为了菜鸟。。
问题点数:50、回复次数:11Top
1 楼viodstatic()回复于 2006-07-02 15:13:30 得分 0
偶在网络上查不了。。没有有解释。。希望CSDN的高手门解决。Top
2 楼jixingzhong(瞌睡虫·星辰)回复于 2006-07-02 16:18:36 得分 0
一般的入门书籍上都会有介绍的 ...
可能一开始不是介绍的很全面,
不过把书都看了,就慢慢会接触到了 ....Top
3 楼jixingzhong(瞌睡虫·星辰)回复于 2006-07-02 16:20:22 得分 0
看了书,如果还没有概念再问 ...
没有看到的东西,
问了,别人的解答也是模棱两可的,
因为自己没有接触理解不深,
没多久就会忘记 ....Top
4 楼changyanxiao(踏雪无情)回复于 2006-07-02 16:20:36 得分 0
买一本c++ primer仔细研读,就搞定了Top
5 楼loomman(一剑)回复于 2006-07-02 16:32:19 得分 0
看钱能的大学教程那本C++书
号称C++百科Top
6 楼OOPhaisky(异化$渴望成功~~)回复于 2006-07-02 19:44:47 得分 0
看看c++ primer或者C++ programming language吧,然后遇到具体的问题再来问Top
7 楼UPCC(杂食动物)回复于 2006-07-02 19:57:54 得分 0
这....自己google,或者买本书把!Top
8 楼fireseed(【VC无敌,英明神武,千秋万代,一统江湖!】—奶油狗)回复于 2006-07-02 20:33:26 得分 0
MSDN里全有
给你几个
=======================================================================
break
The break statement terminates the execution of the nearest enclosing loop or conditional statement in which it appears. Control passes to the statement that follows the terminated statement, if any.
break;
Remarks
break is used with the conditional switch statement and with the do, for, and while loop statements.
In a switch statement, break causes the program to execute the next statement after the switch. Without a break statement, every statement from the matched case label to the end of the switch, including the default, is executed.
In loops, break terminates execution of the nearest enclosing do, for, or while statement. Control passes to the statement that follows the terminated statement, if any.
Within nested statements, the break statement terminates only the do, for, switch, or while statement that immediately encloses it. You can use a return or goto statement to transfer control from within more deeply nested structures.
Example
The following example illustrates the use of the break statement in a for loop.
Copy Code
// break_statement.cpp
#include <stdio.h>
int main()
{
int i;
for (i = 1; i < 10; i++)
{
printf_s("%d\n", i);
if (i == 4)
break;
}
} // Loop exits after printing 1 through 4
Output
1
2
3
4
=======================================================================
enum
Declares a managed enumeration. An enumeration is a user-defined type consisting of a set of named constants called enumerators.
access enum class name [: type] { enumerator-list } var;
access enum struct name [:type] { enumerator-list } var;
Parameters
access
The accessibility of the enum. Can be either public or private.
enumerator-list
A comma-separated list of the identifiers (enumerators) in the enumeration.
name
The name of the enumeration. Anonymous managed enumerations are not allowed.
type (optional)
The underlying type of the identifiers. This can be any scalar type, such as signed or unsigned versions of int, short, or long. bool or char is also allowed.
var (optional)
The name of a variable of the enumeration type.
Remarks
enum class and enum struct are equivalent declarations.
There are two types of enums: managed and standard.
A managed enum might be defined as follows,
Copy Code
enum class day {sun, mon };
and is semantically equivalent to:
Copy Code
ref class day {
public:
static const int sun = 0;
static const int mon = 1;
};
A standard enum might be defined as follows:
Copy Code
enum day2 {sun, mon, };
and is semantically equivalent to:
Copy Code
static const int sun = 0;
static const int mon = 1;
Managed enumerator names (identifiers) are not injected into the scope where the enumeration is defined; all references to the enumerators must be fully qualified (name::identifier). For this reason, you cannot define an anonymous managed enum.
The enumerators of a standard enum are strongly injected into the enclosing scope. That is, if there is another symbol with the same name as an enumerator in the enclosing scope, the compiler will generate an error.
In Visual C++ 2002 and Visual C++ 2003, enumerators were weakly injected (visible in the enclosing scope unless there was another identifier with the same name).
If a standard C++ enum is defined (without class or struct), compiling with /clr will cause the enumeration to be compiled as a managed enum. The enumeration still has the semantics of an unmanaged enumeration. Note, the compiler injects an attribute, Microsoft::VisualC::NativeEnumAttribute, which the Visual C++ compiler recognizes, to identify a programmer's intent for the enum to be a native enum. Other compilers will simply see the standard enum as a managed enum.
A named, standard enum compiled with /clr will be visible in the assembly as a managed enum, and can be consumed by any other managed compiler. However, an unnamed standard enum will not be publicly visible from the assembly.
In Visual C++ 2002 and Visual C++ 2003, a standard enum used as the type in a function parameter:
Copy Code
// mcppv2_enum.cpp
// compile with: /clr
enum E { a, b };
void f(E) {System::Console::WriteLine("hi");}
int main() {
E myi = b;
f(myi);
}
would emit the following in MSIL for the function signature:
Copy Code
void f(int32);
However, in current versions of the compiler, the standard enum is emitted as a managed enum with a [NativeEnumAttribute] and the following in MSIL for the function signature:
Copy Code
void f(E)
For more information about native enums, see C++ Enumeration Declarations.
In the development environment, you can get F1 help on these keywords by highlighting the keyword, (enum class, for example) and pressing F1.
For more information on CLR enums, see:
Underlying Type of an Enum
Managed and Standard Enumerations
Operators and Enumerations
Example
Copy Code
// mcppv2_enum_2.cpp
// compile with: /clr
// managed enum
public enum class m { a, b };
// standard enum
public enum n { c, d };
// unnamed, standard enum
public enum { e, f } o;
int main() {
// consume managed enum
m mym = m::b;
System::Console::WriteLine("no automatic conversion to int: {0}", mym);
System::Console::WriteLine("convert to int: {0}", (int)mym);
// consume standard enum
n myn = d;
System::Console::WriteLine(myn);
// consume standard, unnamed enum
o = f;
System::Console::WriteLine(o);
}
Output
no automatic conversion to int: b
convert to int: 1
1
1
=====================================================
delete
Deallocates a block of memory.
[::] delete cast-expression
[::] delete [ ] cast-expression
Remarks
The cast-expression argument must be a pointer to a block of memory previously allocated for an object created with the new operator. The delete operator has a result of type void and therefore does not return a value. For example:
Copy Code
CDialog* MyDialog = new CDialog;
// use MyDialog
delete MyDialog;
Using delete on a pointer to an object not allocated with new gives unpredictable results. You can, however, use delete on a pointer with the value 0. This provision means that, when new returns 0 on failure, deleting the result of a failed new operation is harmless. See The new and delete Operators for more information.
The new and delete operators can also be used for built-in types, including arrays. If pointer refers to an array, place empty brackets before pointer:
Copy Code
int* set = new int[100];
//use set[]
delete [] set;
Using the delete operator on an object deallocates its memory. A program that dereferences a pointer after the object is deleted can have unpredictable results or crash.
When delete is used to deallocate memory for a C++ class object, the object's destructor is called before the object's memory is deallocated (if the object has a destructor).
If the operand to the delete operator is a modifiable l-value, its value is undefined after the object is deleted.
Example
For examples of using delete, see new operator.
Top
9 楼fireseed(【VC无敌,英明神武,千秋万代,一统江湖!】—奶油狗)回复于 2006-07-02 20:33:49 得分 0
要翻译吗?Top
10 楼cleansunshing(努力学习中)回复于 2006-07-03 10:26:14 得分 0
E文看不懂,HOHOTop
11 楼hongshuangxi(八年抗战_HUSTCEEE2000)回复于 2006-07-03 12:14:19 得分 0
有人原意讲讲explicit和static_cast吗?Top




