AFAIK, Windows is in C because that was what was available back then, but C++ is much more powerful than C. True that you can get things done in C, but you can get things done better in C++.
For example, I wish you good luck trying to manage collections in C. You'll have to use C arrays, meaning you will have to keep dynamically allocating memory, copying data around removing pointers, etc. It is just not worth it. In C++, you could create a simple array class that would do it for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
static const int C_StdCapacityIncrease = 32;
template<class T>
class Array
{
T *_arrPtr;
int m_size;
int _capacity;
int _capacityIncrease;
public:
Array(int initialSize = 0; int capacityIncrease = C_StdCapacityIncrease)
: _arrPtr(initialSize ? new T[initialSize] : 0)
, m_size(initialSize), _capacity(initialSize), _capacityIncrease(capacityIncrease)
{ }
protected:
void IncreaseCapacity()
{
_capacity += capacityIncrease;
T *tempPtr = new T[_capacity];
memcpy(tempPtr, _arrPtr, m_size);
delete[] _arrPtr;
_arrPtr = tempPtr;
}
public:
int Add(const T &item)
{
if (_capacity <= m_size)
{
IncreaseCapacity();
}
_arrPtr[m_size] = item;
return m_size++;
}
void Clear()
{
if (_arrPtr)
{
delete[] _arrPtr;
_arrPtr = 0;
}
}
//Destructor
~Array()
{
Clear();
}
};
| |
That would be just an array class with very basic functionality, of course, and look at all those lines, because all that is needed to properly maintain a C array. In C, you would have to code standalone procedures to take care of all that, like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
//The C way
void* CreateArray(int initialSize, size_t sizeOfItem)
{
return malloc(initialSize * sizeOfItem);
}
void FreeArray(void* arrPtr)
{
free(arrPtr);
}
//etc.
| |
The C way then imposes a lot more work to each array you create: You must ensure you delete memory yourself, you must keep track of sizes and capacities yourself, etc.
And don't even get me started in the elimination of an item in the array in the middle of it. :-S
C++ produces far better code, IMHO.
P. S. : I know that if you are using C++ the best would be to use std::vector. I just made an array class as an example of the complexities that can be abstracted into a class.