- Composite type
computer science, composite types are datatypes which can be constructed in a programming languageout of that language's primitive typesand other composite types. The act of constructing a composite type is known as composition.
C/C++ structures and classes
structis C's and
C++'s notion of a composite type, a datatype that composes a fixed set of labelled fields or members. It is so called because of the
structkeyword used in declaring them, which is short for "structure" or, more precisely, "user-defined data structure".
In C++, the only difference between a
structand a class is the default
access level, which is "private" for classes and "public" for
Note that while classes and the
classkeyword were completely new in C++, the C programming language already had a crude type of
structs. For all intents and purposes, C++
structs form a
structs: virtually all valid C
structs are valid C++
structs with the same semantics.
structdeclaration consists of a list of fields, each of which can have any type. The total storage required for a
structobject is the sum of the storage requirements of all the fields, plus any internal padding.
defines a type, referred to as
struct Account. To create a new variable of this type, we can write
struct Account myAccount;which has an integer component, accessed by
myAccount.account_number, and a floating-point component, accessed by
myAccount.balance, as well as the
last_namecomponents. The structure
myAccountcontains all four values, and all four fields may be changed independently.
struct Accountrepeatedly in code becomes cumbersome, it is not unusual to see a
typedefstatement in C code to provide a more convenient synonym for the
In C++ code, the
typedefis not needed because types defined using
structare already part of the regular namespace, so the type can be referred to as either
struct Accountor simply
As another example, a three-dimensional Vector composite type that uses the floating point data type could be created with:
A variable named
Vectorcomposite type would be declared as
Vector velocity;Members of the
velocitywould be accessed using a dot notation. For example,
velocity.x = 5;would set the
velocityequal to 5.
Likewise, a color structure could be created using:
In 3D graphics, you usually must keep track of both the position and color of each vertex. One way to do this would be to create a
Vertexcomposite type, using the previously created
Create a variable of type
Vertexusing the same format as before:
Assign values to the components of
The primary use of
structis for the construction of complex datatypes, but sometimes it is used to circumvent standard C conventions to create primitive subtyping. For example, common Internet protocols rely on the fact that C compilers insert padding between struct fields in predictable ways; thus the code
will work correctly.
Function types (or type signatures) are constructed from primitive and composite types, and can serve as types themselves when constructing composite types:
Wikimedia Foundation. 2010.
Look at other dictionaries:
composite type — noun A datatype that can be constructed in a programming language out of that languages primitive types and other composite types; exemplified by array, structure, and class. Ant: primitive type … Wiktionary
Composite baseball bat — Composite baseball bats incorporate a recent advancement in the technology of aluminum baseball bats for high school and collegiate players. In general, composite bats are constructed with the same aluminum exterior as standard aluminum baseball… … Wikipedia
Composite data type — In computer science, a composite data type is any data type which can be constructed in a program using its programming language s primitive data types and other composite types. The act of constructing a composite type is known as composition.… … Wikipedia
Composite (New York City Subway car) — Composite 1904 Rendering of an IRT Composite Manufacturer Jewett Car Company St. Louis Car Company Wason Manufacturing Company John Stephenson Company … Wikipedia
Composite — may refer to: Acting, Film, and Studio Composite card, a marketing tool for actors and especially models Composite character, a character in an adaptation of a work formed from two or more characters from the original work Digital compositing or… … Wikipedia
Composite aircraft — can also refer to aircraft made using composite materials. A composite aircraft is made up of multiple component craft. It takes off and flies initially as a single aircraft, with the components able to separate in flight and continue as… … Wikipedia
composite — [ kɔ̃pozit ] adj. et n. m. • 1360; lat. compositus 1 ♦ (1542) Qui participe de plusieurs styles d architecture. Ordre composite. Chapiteau composite. Spécialt Ordre composite, ou n. m. le composite : ordre romain, dans lequel le chapiteau réunit… … Encyclopédie Universelle
Composite monarchy — (from Composite: Made up of separate elements and Monarchy: A state or nation with one supreme power) refers to one ruler of a unified kingdom which either governs each territory as if they were individual kingdoms, in accordance with local… … Wikipedia
Composite Software — Composite Software, Inc. Type Privately Held Industry Computer software Headquarters San Mateo, CA, USA London, UK Area served Americas, Europe Products … Wikipedia
Composite construction — is a generic term to describe any building construction involving multiple dissimilar materials. Composite construction is often used in building aircraft, watercraft, and building construction. There are several reasons to use composite… … Wikipedia