问题:关于C++ 关键字详细解释

viodstatic 2006-07-02 03:11:45
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++,大家一起学习。。

我觉得这个区能引导大家去学好语言才算是语言专业区

偶知道会很大工程,不过为了菜鸟。。
...全文
408 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongshuangxi 2006-07-03
  • 打赏
  • 举报
回复
有人原意讲讲explicit和static_cast吗?
cleansunshing 2006-07-03
  • 打赏
  • 举报
回复
E文看不懂,HOHO
fireseed 2006-07-02
  • 打赏
  • 举报
回复
要翻译吗?
fireseed 2006-07-02
  • 打赏
  • 举报
回复
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.
Dong 2006-07-02
  • 打赏
  • 举报
回复
这....自己google,或者买本书把!
OOPhaisky 2006-07-02
  • 打赏
  • 举报
回复
看看c++ primer或者C++ programming language吧,然后遇到具体的问题再来问
一剑 2006-07-02
  • 打赏
  • 举报
回复
看钱能的大学教程那本C++书
号称C++百科
changyanxiao 2006-07-02
  • 打赏
  • 举报
回复
买一本c++ primer仔细研读,就搞定了
jixingzhong 2006-07-02
  • 打赏
  • 举报
回复
看了书,如果还没有概念再问 ...

没有看到的东西,
问了,别人的解答也是模棱两可的,
因为自己没有接触理解不深,
没多久就会忘记 ....
jixingzhong 2006-07-02
  • 打赏
  • 举报
回复
一般的入门书籍上都会有介绍的 ...

可能一开始不是介绍的很全面,
不过把书都看了,就慢慢会接触到了 ....
viodstatic 2006-07-02
  • 打赏
  • 举报
回复
偶在网络上查不了。。没有有解释。。希望CSDN的高手门解决。

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧