设为首页 加入收藏

TOP

1.5 Introducing Classes (1)
2013-10-07 16:14:52 来源: 作者: 【 】 浏览:60
Tags:1.5 Introducing Classes

The only remaining feature we need to understand before solving our bookstore problemis how to define a data structure to represent our transaction data. In C++(www.cppentry.com) we define our own data structures by defining a class. A class defines a type along with a collection of operations that are related to that type. The class mechanism is one of the most important features in C++(www.cppentry.com). In fact, a primary focus of the design of C++(www.cppentry.com) is to make it possible to define class types that behave as naturally as the built-in types.

In this section, we’ll describe a simple class that we can use in writing our bookstore program. We’ll implement this class in later chapters as we learn more about types, expressions, statements, and functions.

To use a class we need to know three things:

.. What is its name

.. Where is it defined

.. What operations does it support

For our bookstore problem, we’ll assume that the class is named Sales_item and that it is already defined in a header named Sales_item.h.

As we’ve seen, to use a library facility, we must include the associated header. Similarly, we use headers to access classes defined for our own applications. Conventionally, header file names are derived from the name of a class defined in that header. Header files that we write usually have a suffix of .h, but some programmers use .H, .hpp, or .hxx. The standard library headers typically have no suffix at all. Compilers usually don’t care about the form of header file names, but IDEs
sometimes do.

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇1.5 Introducing Classes (2) 下一篇1.2 A First Look at Input/Outpu..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)