I was wondering, why can't there be a void data type that is not a pointer?
Surely you could get past the whole determined size thing by having
void4
void8
void32
And then only being allowed to 'cast' a void data type to another class if its size is equal or under to the classes size.
Is there something that I'm missing, or does the C++ committee just consider it bad practise?
EDIT:
I haven't explained myself very well, so I'll give an example of its use:
main()
{
/*
Lets make a list of unknown elements
std::string is 8 bytes, and float is 4
bytes, so we'll reserve 8 byte sequences
*/
vector<void8> elements;
elements.push_back((void8) string("First string element"));
elements.push_back((void8) float(5.76) );
elements.push_back((void8) string("Third string element"));
// Ect.
cout << (string) elements[0];
cout << (float) elements[1];
cout << (string) elements[2];
cout << (float) elements[2]; // Garbage
void1 data;
data = (void1) bool(1);
data = (void1) unsigned int(80094); // Error, not enough size
}
Its named void because you don't know what type it is currently storing, similar to the void pointer.