Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a scalar Object in C++?

Tags:

c++

types

theory

As far as I understand it fundamental types are Scalar and Arrays are aggregate but what about user defined types? By what criteria would I divide them into the two categories?

struct S { int i; int j }; class C { public: S s1_; S s2_ }; std::vector<int> V; std::vector<int> *pV = &v; 
like image 585
odinthenerd Avatar asked Feb 11 '13 22:02

odinthenerd


People also ask

What is scalar type in C?

“C Scalar Data Types” lists C scalar data types, providing their size and format. The alignment of a scalar data type is equal to its size. “Scalar Alignment” shows scalar alignments that apply to individual scalars and to scalars that are elements of an array or members of a structure or union.

What does scalar mean in programming?

A scalar variable, or scalar field, is a variable that holds one value at a time. It is a single component that assumes a range of number or string values. A scalar value is associated with every point in a space.

What is a scalar data type?

Scalar data are characterized by the fact that they contain a single value. Thus, they are the building blocks of any information that your perl program will store or manipulate. There are two main types of scalar data in perl: string and numeric.

What is a scalar integer?

An integer scalar value consists of one or more digits, optionally preceded by a plus or minus sign and optionally containing underscores.


2 Answers

Short version: Types in C++ are:

  • Object types: scalars, arrays, classes, unions

  • Reference types

  • Function types

  • (Member types) [see below]

  • void


Long version

  • Object types

    • Scalars

      1. arithmetic (integral, float)

      2. pointers: T * for any type T

      3. enum

      4. pointer-to-member

      5. nullptr_t

    • Arrays: T[] or T[N] for any complete, non-reference type T

    • Classes: class Foo or struct Bar

      1. Trivial classes

      2. Aggregates

      3. POD classes

      4. (etc. etc.)

    • Unions: union Zip

  • References types: T &, T && for any object or free-function type T

  • Function types

    • Free functions: R foo(Arg1, Arg2, ...)

    • Member functions: R T::foo(Arg1, Arg2, ...)

  • void

Member types work like this. A member type is of the form T::U, but you can't have objects or variables of member type. You can only have member pointers. A member pointer has type T::* U, and it is a pointer-to-member-object if U is a (free) object type, and a pointer-to-member-function if U is a (free) function type.

All types are complete except void, unsized arrays and declared-but-not-defined classes and unions. All incomplete types except void can be completed.

All types can be const/volatile qualified.

The <type_traits> header provides trait classes to check for each of these type characteristics.

like image 128
Kerrek SB Avatar answered Sep 28 '22 11:09

Kerrek SB


I think this would be a more comprehensive answer:

enter image description here

original document:
http://howardhinnant.github.io/TypeHiearchy.pdf

a scalar is a fundamental except it cannot be void, but it can be a pointer type, or an enum type.

And a fundamental has a keyword in the language. it is easy to recognize when said like that.

like image 30
v.oddou Avatar answered Sep 28 '22 12:09

v.oddou