什么是C ++中的对象? [英] What is exactly an object in C++?

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

问题描述

在学习C ++的初期,我认为一个对象是一个仅与OOP相关的术语。但是,我学得越多,阅读的内容越多,我发现情况并非如此,而且我发现对象一词具有更广泛的含义。我在网上阅读了很多资料,但仍找不到清晰/可靠的内容。可能是我找不到正确的地方。我可以获得标准,并且对此有很好的段落,但是您可能知道标准语言有点困难。

In the beginning of my journey learning C++, I thought an object is an OOP-only related term. However, the more I learn and the more I read, I can see that this not the case, and I can find that the term "object" has a more generalized meaning. I read a lot of materials on the net, but I could not yet find something clear/solid. May be I could not get to the correct place. I could get the standards and it has good paragraphs about this, but as you may know standard language is a bit difficult. and the information usually too scattered.

我的问题:您能用简单的英文给我看吗?在OOP世界之外C ++中的对象是什么?

My question: would you please show me in a simple English What is an object in C++ outside the OOP world?

推荐答案

C ++ 11 标准非常明确:


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

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

对象是存储区域。 [注意:函数不是对象,无论它是否以对象的方式占用存储空间。 —尾注]

An object is a region of storage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do. — end note ]

就是这样。对象是可以存储数据的内存块。

That's it. An object is a chunk of memory in which data can be stored.

如果您想到的是 OO O bject O 的方向更有意义。

If you think about it OO or Object Orientation makes more sense when you realize that in the old days the programs were organized around the functions which operated upon the objects (or data).

术语对象在对象方向之前大约

什么对象方向确实是将程序组织从围绕功能进行组织转变为围绕数据本身-对象进行组织。

What object orientation did was change the program organization from being organized around the functions to being organized around the data itself - the objects.

因此,面向对象一词。

范式的改变

在这里我们看到了范式从旧的转变天:

Here we see the paradigm shift from the old days:

struct my_object
{
    int i;
    char s[20];
};

void function(my_object* o)
{
    // function operates on the object (procedural / procedure oriented)
}

我们现在所拥有的:

struct my_object
{
    void function()
    {
        // object operates on itself (Object Oriented)
    }

    int i;
    char s[20];
};

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

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