C Classes
   HOME

TheInfoList



OR:

A class in C++ is a user-defined type or
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, a ...
declared with
keyword Keyword may refer to: Computing * Keyword (Internet search), a word or phrase typically used by bloggers or online content creator to rank a web page on a particular topic * Index term, a term used as a keyword to documents in an information syst ...
class that has data and functions (also called
member variable In object-oriented programming, a member variable (sometimes called a member field) is a variable that is associated with a specific object, and accessible for all its methods (''member functions''). In class-based programming languages, these are ...
s and
member function A method in object-oriented programming (OOP) is a procedure associated with a message and an object. An object consists of ''state data'' and ''behavior''; these compose an ''interface'', which specifies how the object may be utilized by any of ...
s) as its members whose access is governed by the three
access specifier Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Access modifiers are a specific part of programming language syntax used to facilitate the enca ...
s ''private'', ''protected'' or ''public''. By default access to members of a C++ class is ''private''. The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an
interface Interface or interfacing may refer to: Academic journals * ''Interface'' (journal), by the Electrochemical Society * '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics'' * '' Int ...
to the class and are accessible outside the class. Instances of a class data type are known as
objects Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ...
and can contain member variables, constants, member functions, and overloaded operators defined by the programmer.


Differences between a structure and a class in C++

In C++, a class defined with the class keyword has
private Private or privates may refer to: Music * " In Private", by Dusty Springfield from the 1990 album ''Reputation'' * Private (band), a Denmark-based band * "Private" (Ryōko Hirosue song), from the 1999 album ''Private'', written and also recorde ...
members and base classes by default. A structure is a class defined with the struct keyword.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §9 Classes
lass Lass may refer to: *A girl/young woman in Scottish/Northern English People Surname *August Lass (1903–1962), Estonian footballer * Barbara Kwiatkowska-Lass (1940–1995), Polish actress *Donna Lass (1944–' 1970), possible victim of the Zodiac ...
' para. 4
Its members and base classes are
public In public relations and communication science, publics are groups of individual people, and the public (a.k.a. the general public) is the totality of such groupings. This is a different concept to the sociological concept of the ''Öffentlichkei ...
by default. In practice, structs are typically reserved for data without functions. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public. And when deriving a class, default access specifier is private.


Aggregate classes

An aggregate class is a class with no user-declared constructors, no private or protected non-static data members, no base classes, and no virtual functions.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §8.5.1 Aggregates cl.init.aggr' para. 1
Such a class can be initialized with a brace-enclosed comma-separated list of initializer-clauses.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §8.5.1 Aggregates cl.init.aggr' para. 2
The following code has the same semantics in both C and C++. struct C ; struct D ; // initialize an object of type C with an initializer-list C c = ; // D has a sub-aggregate of type C. In such cases initializer-clauses can be nested D d = ;


POD-structs

A POD-struct (Plain Old Data Structure) is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined
assignment operator Assignment, assign or The Assignment may refer to: * Homework * Sex assignment * The process of sending National Basketball Association players to its development league; see Computing * Assignment (computer science), a type of modification t ...
and no user-defined destructor. A POD-struct could be said to be the C++ equivalent of a C struct. In most cases, a POD-struct will have the same memory layout as a corresponding struct declared in C. For this reason, POD-structs are sometimes colloquially referred to as "C-style structs".


Properties shared between structs in C and POD-structs in C++

*Data members are allocated so that later members have higher addresses within an object, except where separated by an access-specifier.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §9.2 Class members lass.mem' para. 12
*Two POD-struct types are layout-compatible if they have the same number of nonstatic data members, and corresponding nonstatic data members (in order) have layout-compatible types.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §9.2 Class members lass.mem' para. 14
*A POD-struct may contain unnamed
padding Padding is thin cushioned material sometimes added to clothes. Padding may also be referred to as batting when used as a layer in lining quilts or as a packaging or stuffing material. When padding is used in clothes, it is often done in an attempt ...
.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §9.2 Class members lass.mem' para. 17
*A pointer to a POD-struct object, suitably converted using a reinterpret cast, points to its initial member and vice versa, implying that there is no padding at the beginning of a POD-struct. *A POD-struct may be used with the
offsetof C's macro is an ANSI C library feature found in . It evaluates to the offset (in bytes) of a given member within a struct or union type, an expression of type . The offsetof() macro takes two parameters, the first being a structure name, and the ...
macro.
ISO ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
/
IEC The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
(2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ §18.1 Types ib.support.types' para. 5


Declaration and usage

C++ classes have their own members. These members include variables (including other structures and classes), functions (specific identifiers or overloaded operators) known as methods, constructors and destructors. Members are declared to be either publicly or privately accessible using the public: and private: access specifiers respectively. Any member encountered after a specifier will have the associated access until another specifier is encountered. There is also inheritance between classes which can make use of the protected: specifier.


Global and local class

A class defined outside all methods is a global class because its objects can be created from anywhere in the program. If it is defined within a function body then it's a local class because objects of such a class are local to the function scope.


Basic declaration and member variables

Classes are declared with the class or struct
keyword Keyword may refer to: Computing * Keyword (Internet search), a word or phrase typically used by bloggers or online content creator to rank a web page on a particular topic * Index term, a term used as a keyword to documents in an information syst ...
. Declaration of members are placed within this declaration. The above definitions are functionally equivalent. Either code will define objects of type Person as having two public data members, name and age. The
semicolon The semicolon or semi-colon is a symbol commonly used as orthographic punctuation. In the English language, a semicolon is most commonly used to link (in a single sentence) two independent clauses that are closely related in thought. When a ...
s after the closing braces are mandatory. After one of these declarations (but not both), Person can be used as follows to create newly defined variables of the Person datatype: #include #include struct Person ; int main() Executing the above code will output Calvin: 30 Hobbes: 20


Member functions

An important feature of the C++ class and structure are member functions. Each datatype can have its own built-in functions (referred to as methods) that have access to all (public and private) members of the datatype. In the body of these non-static member functions, the keyword this can be used to refer to the object for which the function is called. This is commonly implemented by passing the address of the object as an implicit first argument to the function. Take the above Person type as an example again: #include class Person ; void Person::Print() const In the above example the Print function is declared in the body of the class and defined by qualifying it with the name of the class followed by ::. Both name_ and age_ are private (default for class) and Print is declared as public which is necessary if it is to be used from outside the class. With the member function Print, printing can be simplified into: a.Print(); b.Print(); where a and b above are called senders, and each of them will refer to their own member variables when the Print() function is executed. It is common practice to separate the class or structure declaration (called its interface) and the definition (called its implementation) into separate units. The interface, needed by the user, is kept in a header and the implementation is kept separately in either
source Source may refer to: Research * Historical document * Historical source * Source (intelligence) or sub source, typically a confidential provider of non open-source intelligence * Source (journalism), a person, publication, publishing institute o ...
or compiled form.


Inheritance

The layout of non-POD classes in memory is not specified by the C++ standard. For example, many popular C++ compilers implement single
inheritance Inheritance is the practice of receiving private property, Title (property), titles, debts, entitlements, Privilege (law), privileges, rights, and Law of obligations, obligations upon the death of an individual. The rules of inheritance differ ...
by concatenation of the parent class fields with the child class fields, but this is not required by the standard. This choice of layout makes referring to a derived class via a pointer to the parent class type a trivial operation. For example, consider struct P ; struct C : P ; An instance of P with a P* p pointing to it might look like this in memory: ┏━━━━┓ ┃P::x┃ ┗━━━━┛ ↑ p An instance of C with a P* p pointing to it might look like this: ┏━━━━┳━━━━┓ ┃P::x┃C::y┃ ┗━━━━┻━━━━┛ ↑ p Therefore, any code that manipulates the fields of a P object can manipulate the P fields inside the C object without having to consider anything about the definition of C's fields. A properly written C++ program shouldn't make any assumptions about the layout of inherited fields, in any case. Using the static_cast or dynamic_cast
type conversion In computer science, type conversion, type casting, type coercion, and type juggling are different ways of changing an expression from one data type to another. An example would be the conversion of an integer value into a floating point value ...
operators will ensure that pointers are properly converted from one type to another. Multiple inheritance is not as simple. If a class D inherits P and C, then the fields of both parents need to be stored in some order, but (at most) only one of the parent classes can be located at the front of the derived class. Whenever the compiler needs to convert a pointer from the D type to either P or C, the compiler will provide an automatic conversion from the address of the derived class to the address of the base class fields (typically, this is a simple offset calculation). For more on multiple inheritance, see
virtual inheritance Virtual inheritance is a C++ technique that ensures only one copy of a base classs member variables are inherited by grandchild derived classes. Without virtual inheritance, if two classes B and C inherit from a class A, and a class D inherits fr ...
.


Overloaded operators

In C++, operators, such as + - * /, can be overloaded to suit the needs of programmers. These operators are called overloadable operators. By convention, overloaded operators should behave nearly the same as they do in built-in datatypes (int, float, etc.), but this is not required. One can declare a structure called Integer in which the variable ''really'' stores an integer, but by calling Integer * Integer the sum, instead of the product, of the integers might be returned: struct Integer ; The code above made use of a constructor to "construct" the return value. For clearer presentation (although this could decrease efficiency of the program if the compiler cannot optimize the statement into the equivalent one above), the above code can be rewritten as: Integer operator*(const Integer& k) const Programmers can also put a prototype of the operator in the struct declaration and define the function of the operator in the global scope: struct Integer ; Integer Integer::operator*(const Integer& k) const i above represents the sender's own member variable, while k.i represents the member variable from the argument variable k. The const keyword appears twice in the above code. The first occurrence, the argument const integer& k, indicated that the argument variable will not be changed by the function. The second incidence at the end of the declaration promises the
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
that the sender would not be changed by the function run. In const integer& k, the
ampersand The ampersand, also known as the and sign, is the logogram , representing the conjunction "and". It originated as a ligature of the letters ''et''—Latin for "and". Etymology Traditionally in English, when spelling aloud, any letter that ...
(&) means "pass by reference". When the function is called, a reference to the variable will be passed to the function, rather than the value of the variable. The same overloading properties above apply also to classes. Note that
arity Arity () is the number of arguments or operands taken by a function, operation or relation in logic, mathematics, and computer science. In mathematics, arity may also be named ''rank'', but this word can have many other meanings in mathematics. In ...
,
associativity In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
and precedence of operators cannot be changed.


Binary overloadable operators

Binary operators (operators with two arguments) are overloaded by declaring a function with an "identifier" ''operator (something)'' which calls one single argument. The variable on the left of the operator is the sender while that on the right is the argument. Integer i = 1; /* we can initialize a structure variable this way as if calling a constructor with only the first argument specified. */ Integer j = 3; /* variable names are independent of the names of the member variables of the structure. */ Integer k = i * j; std::cout << k.i << '\n'; '3' would be printed. The following is a list of binary overloadable operators: The '=' (assignment) operator between two variables of the same structure type is overloaded by default to copy the entire content of the variables from one to another. It can be overwritten with something else, if necessary. Operators must be overloaded one by one, in other words, no overloading is associated with one another. For example, < is not necessarily the opposite of >.


Unary overloadable operators

While some operators, as specified above, takes two terms, sender on the left and the argument on the right, some operators have only one argument - the sender, and they are said to be "unary". Examples are the negative sign (when nothing is put on the left of it) and the "logical NOT" (
exclamation mark The exclamation mark, , or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, f ...
, !). Sender of unary operators may be on the left or on the right of the operator. The following is a list of unary overloadable operators: The syntax of an overloading of a unary operator, where the sender is on the right, is as follows: :''return_type'' operator@ () When the sender is on the left, the declaration is: :''return_type'' operator@ (int) @ above stands for the operator to be overloaded. Replace return_type with the datatype of the return value (int, bool, structures etc.) The int parameter essentially means nothing but a convention to show that the sender is on the left of the operator. const arguments can be added to the end of the declaration if applicable.


Overloading brackets

The square bracket [] and the round bracket () can be overloaded in C++ structures. The square bracket must contain exactly one argument, while the round bracket can contain any specific number of arguments, or no arguments. The following declaration overloads the square bracket. :''return_type'' operator[] (''argument'') The content inside the bracket is specified in the argument part. Round bracket is overloaded a similar way. :''return_type'' operator() (''arg1, arg2, ...'') Contents of the bracket in the operator call are specified in the second bracket. In addition to the operators specified above, the arrow operator (->), the starred arrow (->*), the new keyword and the delete keyword can also be overloaded. These memory-or-pointer-related operators must process memory-allocating functions after overloading. Like the assignment (=) operator, they are also overloaded by default if no specific declaration is made.


Constructors

Sometimes programmers may want their variables to take a default or specific value upon declaration. This can be done by declaring constructors. Person::Person(string name, int age) Member variables can be initialized in an initializer list, with utilization of a colon, as in the example below. This differs from the above in that it initializes (using the constructor), rather than using the assignment operator. This is more efficient for class types, since it just needs to be constructed directly; whereas with assignment, they must be first initialized using the default constructor, and then assigned a different value. Also some types (like references and types) cannot be assigned to and therefore must be initialized in the initializer list. Person(std::string name, int age) : name_(name), age_(age) Note that the curly braces cannot be omitted, even if empty. Default values can be given to the last arguments to help initializing default values. Person(std::string name = "", int age = 0) : name_(name), age_(age) When no arguments are given to the constructor in the example above, it is equivalent to calling the following constructor with no arguments (a default constructor): Person() : name_(""), age_(0) The declaration of a constructor looks like a function with the same name as the datatype. In fact, a call to a constructor can take the form of a function call. In that case an initialized Person type variable can be thought of as the return value: int main() An alternate syntax that does the same thing as the above example is int main() Specific program actions, which may or may not relate to the variable, can be added as part of the constructor. Person() With the above constructor, a "Hello!" will be printed when the default Person constructor is invoked.


Default constructor

Default constructors are called when constructors are not defined for the classes. struct A ; // Object created using parentheses. A* a = new A(); // Calls default constructor, and b will be initialized with '0'. // Object created using no parentheses. A* a = new A; // Allocate memory, then call default constructor, and b will have value '0'. // Object creation without new. A a; // Reserve space for a on the stack, and b will have an unknown garbage value. However, if a ''user defined constructor'' was defined for the class, both of the above declarations will call this user defined constructor, whose defined code will be executed, but no default values will be assigned to the variable b.


Destructors

A destructor is the inverse of a constructor. It is called when an instance of a class is destroyed, e.g. when an object of a class created in a block (set of curly braces "") is deleted after the closing brace, then the destructor is called automatically. It will be called upon emptying of the memory location storing the variables. Destructors can be used to release resources, such as heap-allocated memory and opened files when an instance of that class is destroyed. The syntax for declaring a destructor is similar to that of a constructor. There is no return value and the name of the method is the same as the name of the class with a tilde (~) in front. ~Person()


Similarities between constructors and destructors

*Both have same name as the class in which they are declared. *If not declared by user both are available in a class by default but they now can only allocate and deallocate memory from the objects of a class when an object is declared or deleted. *For a derived class: During the runtime of the base class constructor, the derived class constructor has not yet been called; during the runtime of the base class destructor, the derived class destructor has already been called. In both cases, the derived class member variables are in an invalid state.


Class templates

In C++, class declarations can be generated from class templates. Such class templates represent a family of classes. An actual class declaration is obtained by ''instantiating'' the template with one or more template arguments. A template instantiated with a particular set of arguments is called a template specialization.


Properties

The
syntax In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure ( constituency) ...
of C++ tries to make every aspect of a structure look like that of the basic datatypes. Therefore, overloaded operators allow structures to be manipulated just like integers and floating-point numbers,
arrays An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
of structures can be declared with the square-bracket syntax (some_structure variable_name
ize Oxford spelling (also ''Oxford English Dictionary'' spelling, Oxford style, or Oxford English spelling) is a spelling standard, named after its use by the University of Oxford, that prescribes the use of British spelling in combination with th ...
/code>), and pointers to structures can be dereferenced in the same way as pointers to built-in datatypes.


Memory consumption

The memory consumption of a structure is at least the sum of the memory sizes of constituent variables. Take the TwoNums structure below as an example. struct TwoNums ; The structure consists of two integers. In many current C++ compilers, integers are 32-bit integers by default, so each of the member variables consume four bytes of memory. The entire structure, therefore, consumes at least (or exactly) eight bytes of memory, as follows. +----+----+ , a , b , +----+----+ However, the compiler may add padding between the variables or at the end of the structure to ensure proper data alignment for a given computer architecture, often padding variables to be 32-bit aligned. For example, the structure struct BytesAndSuch ; could look like +-+-+-+-+--+--+----+--------+ , c, C, D, X, s , XX, i , d , +-+-+-+-+--+--+----+--------+ in memory, where represents padded bytes based on 4 bytes alignment. As structures may make use of pointers and arrays to
declare ''Declare'' (2000) is a supernatural spy novel by American author Tim Powers. The novel presents a secret history of the Cold War, and earned several major fantasy fiction awards. Plot summary The non-linear plot, shifting back and forth in tim ...
and initialize its member variables, memory consumption of structures is not necessarily constant. Another example of non-constant memory size is template structures.


Bit fields

Bit fields are used to define the class members that can occupy less storage than an integral type. This field is applicable only for integral types (int, char, short, long, etc.) and excludes float or double. struct A ; * Memory structure
	 4 byte int  4 byte int
	 2] 4] 6] 8]
	                                                                   	 a] b]  ]  ]   ]  ]  ]  ]   ]  ]  ]  ]   ]  ]  ]  ]

	                                                                   	 c]  ]  ] e]  e]  ]  ]  ]   ]  ]  ]  ]   ]  ]  ]  ]
Bit fields are not allowed in a union. It is applicable only for the classes defined using the keyword struct or class.


Pass by reference

Many programmers prefer to use the ampersand (&) to declare the arguments of a function (mathematics), function involving structures. This is because by using the dereferencing ampersand only one word (typically 4 bytes on a 32 bit machine, 8 bytes on a 64 bit machine) is required to be passed into the function, namely the memory location to the variable. Otherwise, if pass-by-value is used, the argument needs to be copied every time the function is called, which is costly with large structures. Since pass-by-reference exposes the original structure to be modified by the function, the const keyword should be used to guarantee that the function does not modify the parameter (see
const-correctness In some programming languages, const is a type qualifier (a keyword applied to a data type) that indicates that the data is read-only. While this can be used to declare constants, in the C family of languages differs from similar constructs in ...
), when this is not intended.


The ''this'' keyword

To facilitate structures' ability to reference themselves, C++ implements the this keyword for all member functions. The this keyword acts as a pointer to the current object. Its type is that of a pointer to the current object. The this keyword is especially important for member functions with the structure itself as the return value: Complex& operator+=(const Complex& c) As stated above, this is a pointer, so the use of the
asterisk The asterisk ( ), from Late Latin , from Ancient Greek , ''asteriskos'', "little star", is a typographical symbol. It is so called because it resembles a conventional image of a heraldic star. Computer scientists and mathematicians often voc ...
(*) is necessary to convert it into a reference to be returned.


See also

*
Access modifiers Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Access modifiers are a specific part of programming language syntax used to facilitate the enc ...
*
Virtual inheritance Virtual inheritance is a C++ technique that ensures only one copy of a base classs member variables are inherited by grandchild derived classes. Without virtual inheritance, if two classes B and C inherit from a class A, and a class D inherits fr ...
*
Class (computer programming) In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). In many languages, the class n ...
*
Class-based programming Class-based programming, or more commonly class-orientation, is a style of object-oriented programming (OOP) in which inheritance occurs via defining ''classes'' of objects, instead of inheritance occurring via the objects alone (compare prototy ...
*
Object composition In computer science, object composition and object aggregation are closely related ways to combine objects or data types into more complex ones. In conversation the distinction between composition and aggregation is often ignored. Common kind ...
*
Type conversion In computer science, type conversion, type casting, type coercion, and type juggling are different ways of changing an expression from one data type to another. An example would be the conversion of an integer value into a floating point value ...


References

General References:
Cplusplus.com tutorial lesson 5.2
accessed in January 2006

accessed in February 2006 {{DEFAULTSORT:C++ Classes Articles with example C++ code C++ Class (computer programming)