`
xuning2516
  • 浏览: 7563 次
  • 性别: Icon_minigender_1
  • 来自: 江西
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

C++ first-class object概念

 
阅读更多

C++ standard library P132看到一个新的概念first-class object.但是什么是first-class object?

下面是来自维基百科的解释:

A first-class object is one that can be dynamically created, destroyed or passed as an argument.So, for example, all objects in C++ are also first-class objects. They can be created or destroyed through use of constructor or destructor methods, respectively, and be passed as arguments to functions. However, functions and methods in C++ are not first-class, as they cannot be created at runtime.In functional languages, functions are first-class objects, as they can be passed around as arguments to other functions and can be created dynamically at run-time.In C++, classes are not first class -- though in some languages (LISP's CLOS, for example) they are (as classes are objects).
first-class object:(programming, languages) An entity [that can be constructed at run-time,] passed as a parameter, returned from a subroutine, or assigned into a variable.//first-class object是可以在运行时构造,可以作为参数进行传递,可以从子程序返回,或者赋值给变量。一个就是一种实体。当出现如下情况时,一个对象就成为 FCO:可以保存在变量和数据结构中;可以作为参数传递给子过程;可以作为子过程的运算结果返回;可以在运行时被构建;具有内在的一致性(独立于任何给定的名称)。
这里的“对象”不是严格意义上的,不一定是面向对象编程中的“对象”。最简单的标量数据类型,如整型和浮点型,几乎永远是first-class
(programming, languages) An entity that can pass a value as a parameter, can be returned from a subroutine, and can be assigned into a variable. (This is the definition according to Raphael Finkel, who uses the terms of second- and third-class objects.)

相关概念:
second-class object:(programming, languages)An entity of which the value can be passed as a parameter, but that can neither be returned from a function, nor can it be assigned to a variable.

third-class object: (programming, languages) An entity of which the value can neither be passed as a parameter, nor be returned from a function, nor assigned to a variable.

总结:

Manipulation First Second Third
Pass value as a parameter yes yes no
Return value from a procedure yes no no
Assign value into a variable yes no no
看了这么多回到第132页
std::vector<Myclass&> coll;                          //error
std::vector<std::reference_wrapper<Myclass>> coll;
我们知道vector所能存储的数据类型必须满足:1 元素类型支持赋值;2 我们必须能够拷贝元素类型的对象。但是引用类型并不支持赋值操作。所以第一个语句是错误的。
分享到:
评论

相关推荐

    Biblio.Distribution.C++.For.Artists.The.Art.Philosophy.and.Science.of.Object-Oriented.Programming.2003.chm

    C++ For Artists: The Art, Philosophy, and Science of Object-Oriented Programming by Rick Miller ISBN:1932504028 Biblio Distribution ? 2003 (590 pages) Intended as both a classroom and reference ...

    A First Book Of C++ (4th Edition)

    • The four chapters covering object-oriented programming have been revised and moved to Part II so that they form a logical continuation from structured programming to object-oriented programming. •...

    Object- Oriented Programming with Ansi-C

    The first six chapters develop the foundations of object-oriented programming with ANSI-C. We start with a careful information hiding technique for abstract data types, add generic functions based on ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Other C++ Features Reference Arguments Function Overloading Default Arguments Variable-Length Arrays and alloca() Friends Exceptions Run-Time Type Information (RTTI) Casting Streams Preincrement and ...

    Rad Studio Delphi C++builder XE 10.4 Patch2

    RSP-20372 A generic "reference to function" will only match the first of several overloaded functions RSP-19714 Win32 compiler - Memory corruption with array helpers RSP-18241 *.c source files, added ...

    Exploring C++ 11

    Part 2: Custom Types – Introduction to Object-Oriented Programming Part 2: Custom Types – Inheritance Part 2: Custom Types – Virtual Functions Part 2: Custom Types – Classes and Types Part 2: ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX Class TPenProp rewrote without TPen delphi object. - FIX In some cases TFlexCurve.Paint leaves selected black pen in the canvas which then affects on next flex-control output (in particular ...

    log4cplus 源码(C++编写的开源的日志系统)

    log4cplus是C++编写的开源的日志系统,功能非常全面,用到自己开发的工程中会比较专业的,:),本文介绍了log4cplus基本概念,以及如何安装,配置。 ### 简介 ### log4cplus是C++编写的开源的日志系统,前身是java...

    Prentice.Hall.C++.for.Business.Programming.2nd.Edition.2005.chm

    Part II: Object-Oriented Programming 426 Chapter 10. The string Class: An Introduction to Classes and Objects 426 Section 10.1. Objects, Classes, and Object-Oriented Systems 427 Section 10.2. ...

    c++基础教程,简洁扼要

    因为在C++中类和数据结构的概念太相似了,所以这两个关键字struct和class的作用几乎是一样的(也就是说在C++中struct定义的 类也可以有成员函数,而不仅仅有数据成员)。两者定义的类的唯一区别在于由class定义的类...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持Delphi 4-XE5 and C++Builder 6-XE5. D2010以上版本(D14_D19)安装必读 delphi2010以上版本(D14_D19)使用者安装时,请将res\frccD14_...

    C++ 标准 ISO 14882-2011

    1.8 The C++ object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.9 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

    Senfore_DragDrop_v4.1

    Earlier versions of Delphi and C++ Builder will not be supported. If you need Delphi 3 or C++ Builder 3 support you will have to revert to version 3.7 of the Drag and Drop Component Suite. The ...

    ICS delphixe10源码版

    .\Packages (was Delphi\Vc32) Delphi (7 and up) and C++Builder (2006 and up) packages projects .\Source (was Delphi\Vc32) ICS Delphi source code built into packages .\Source\Include (was Delphi\Vc32) ....

    Visual C++课程设计案例精编(第二版)--第十章 24点游戏软件的开发

    // After loading this object if it contains variables you should atach a variable // Table to it } } int CExpression::UpdateArbore() { if (m_definitie.IsEmpty()) return 0; elibmem(m_Arbore...

    JAVA白皮书(英文版)

    3.3.2Instantiating an Object from its Class 3.3.3Constructors 3.3.4Methods and Messaging 3.3.5Finalizers 3.3.6Subclasses 3.3.7Java Language Interfaces 3.3.8Access Control 3.3.9Packages ...

    Essential LINQ

    Calvert and Kulkarni begin by clearly explaining how LINQ resolves the long-time “impedance mismatch” between object-oriented code and relational databases. Next, they show how LINQ integrates ...

    Guide to Scientific Computing in C++

    1.1.1 C++ is “Object-Oriented” . . . . . . . . . . . . . . . . 1.1.2 Why You Should Write Scientific Programs in C++ . . 1.1.3 Why You Should Not Write Scientific Programs in C++ 1.1.4 Scope of This...

    Google C++ International Standard.pdf

    4.5 The C++ object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.6 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

Global site tag (gtag.js) - Google Analytics