Hey everyone. I had another question about C++. So they introduced static_cast<type>, dynamic_cast<type>, etc to the language. The examples I see typically use the new casts when casting a class that is pointed to into its base class, but not for casting C++ built in types such as int, char, float, etc.
Is the current preffered method to use the original type casting provided with the language for built in types or now use static_cast<type> instead?
In the example below, GetNumberOfPackedFiles() returns an int value. However, i will be used to reference a location in a C++ container that uses size_t for storage position.
for (size_t i = 0; i < static_cast<size_t>(archiveFile.GetNumberOfPackedFiles()); ++i)
{
... do work that wants to use i as a size_t when accessing the contents of a container ...
}
- OR -
for (size_t i = 0; i < (size_t)archiveFile.GetNumberOfPackedFiles(); ++i)
{
... do work that wants to use i as a size_t when accessing the contents of a container ...
}
Thanks,
Brett