static_cast example

// File: static_cast.cpp

int main()
{
	int i = 5;
	double d = 3.14;

	i = d;		// Warning:  conversion from 'double' to 'int', possible loss of data
	i = static_cast<int>(d);			// No warning

	d = i;					// ok

	enum color { red, white, blue };

	// color hue = 1;				// compile error
	color hue = static_cast<color>(1);		// ok

	i = white;					// ok 

	int* ptr_int;
	// ptr_int = &d;				// compile error
	// ptr_int = static_cast<int*>(&d);		// compile error

	return 0;
}