A POD-type is a "Plain 'Ol Data" type, which is any non-user defined type.
So char, signed char, unsigned char, int, unsigned int, long, unsigned long,
(long long and unsigned long long if your compiler supports it), bool, and
any pointer type (can be a pointer to anything, including a user defined type).
You might find this answer in the template section of the book. This syntax
was added to the language to solve the following problem:
1 2 3 4 5 6 7 8 9
|
template< typename T >
class Foo
{
public:
Foo() {}
private:
T value;
};
|
If T is not a POD-type, then T's default constructor will initialize value. For example, if T
is a std::string, we know that a default constructed value will be an empty string. Or if
T is a std::vector<int>, we know that a default constructed value will be a vector containing
zero elements.
But what if T is an int? The "default" constructor for int does nothing, leaving value uninitialized.
Ideally we'd like it initialized. The solution is this:
1 2 3 4 5 6 7 8 9
|
template< typename T >
class Foo
{
public:
Foo() : value() {} // <--- Note the change here
private:
T value;
};
|
This syntax initializes value to the binary equivalent of 0 if T is a POD-type. Otherwise, it runs the
default constructor for T if T is not a POD-type, just like the first example did.
This syntax can also be used on new:
1 2
|
int* p = new int(); // Set *p to 0
int* p = new int(42); // Set *p to 42
|