什么是匿名对象? [英] What is an Anonymous Object?

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

问题描述

什么是匿名对象?

C ++支持/有匿名对象吗?

Does C++ support/have Anonymous Objects?

推荐答案

C ++标准没有定义术语匿名对象,但是它可以理智地使用该术语来描述没有名称的任何对象:

The C++ standard does not define the term "anonymous object", but it stands to reason that one might sanely use the term to describe any object that has no name:


  • 暂时: f(T());

  • void func(int,int,int);

  • Temporaries: f(T());
  • Unnamed function parameters: void func(int, int, int);

em> 不是

What I wouldn't count is dynamically-allocated objects:

从技术上讲,对象是任何存储区域[ ,其中包括组成由 new int;

Technically speaking, an "object" is any region of storage [1.8/1 in 2003], which would include the X bytes making up the integer dynamically-allocated by new int;.

int * ptr = new int; 指针(本身也是一个对象,不要忘记!)名称 ptr 整数本身没有除 * ptr 之外的名称。仍然,我会犹豫将其称为匿名对象。

In int* ptr = new int; the pointer (itself an object too, don't forget!) has the name ptr and the integer itself has no name other than *ptr. Still, I'd hesitate to call this an anonymous object.

但是,没有标准术语。

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

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