所有的异常都是c ++中的对象? [英] All exceptions are objects in c++?

查看:170
本文介绍了所有的异常都是c ++中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些文献中,如 http://en.wikibooks.org/wiki / C%2B%2B_Programming / Exception_Handling ,它们将所有异常视为对象,即使它们抛出一个基本类型或指针。



问为什么我们称之为对象,如果有时它们不是对象。
如果我不能正确理解,请纠正我。

解决方案


Q:我想问为什么我们称之为对象,如果有时它们不是
对象


任何占用内存的东西都是一个对象。 $ b $
$ b

很明显,只有用户定义的类型允许你这样做,但不能阻止基本类型成为对象。



根据 C ++ 11 标准:



1.8 C ++对象模型[ intro.object ]


+程序创建,销毁,引用,访问,
和操纵对象。



p> 对象(计算机科学)


在计算机科学中,对象是存储器中具有值
并且可能由标识符引用的位置。一个对象可以是一个变量,
一个数据结构,或一个函数。在基于类的面向对象的
编程范例中,object是指
类的特定实例,其中对象可以是变量,函数,
和数据结构的组合。



In some literature, like http://en.wikibooks.org/wiki/C%2B%2B_Programming/Exception_Handling , they treat all exceptions as objects, even if they are throwing a fundamental type or a pointer.

I want to ask why we call them objects, if sometimes they are not objects. If i don't understand correctly, please correct me.

解决方案

Q: "I want to ask why we call them objects, if sometimes they are not objects"

Anything that occupies memory is an object. The point of object orientation is to shift the focus on to the data (object) by binding the operations the data accepts with the data itself.

Obviously only user defined types allow you to do this programatically but that doesn't stop fundamental types from being objects.

According to the C++11 standard:

1.8 The C++ object model [intro.object]

1 The constructs in a C ++ program create, destroy, refer to, access, and manipulate objects. An object is a region of storage.

Here is what Wikipedia says:

Object (computer science)

In computer science, an object is a location in memory having a value and possibly referenced by an identifier. An object can be a variable, a data structure, or a function. In the class-based object-oriented programming paradigm, "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures.

这篇关于所有的异常都是c ++中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆