I was wondering why can't there be a void data type that is not a pointer?
Of course, you could pass a target of a certain size, having
void4 void8 void32
And then it is only allowed to "pour" the void data type into another class if its size is equal to or less than the size of the classes.
Is there something that I am missing, or does the C ++ committee simply consider this a bad practice?
EDIT:
I didn’t explain 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 currently stores, similar to the void pointer.
, "" . C ++ " " ( ), ", " ( ).
", , ", , . , ( ), , :
struct void8 { char bytes[8]; };
reinterpret_cast, POD , , . -POD-, , undefined, void*, -POD-.
reinterpret_cast
void*
, , , - boost::any, . "void" ++.
boost::any
boost:: variant boost:: any. + sizeof () .
"void"? , , , , .
? , . Void32, lol! void , . "procedure" "sub". void - ( void). .
: , . void32 * - - 32 , void8 * - 8- .. int32 *, char * .
, , . char. char , char - ++ . , , , , void .
char
void
void , , . , . void4 . "", . , , . , , POD, , . , , . , , , void.
void4
, , :
T?
void foo(void* p) { T q = *p; }
void4? void32? void? ? ? POD?
void32
void . , , void.
, , , void.
void* , , . , .
void . . .
, , . . .
, , int, . - .
int
void "" , void. , void . void .
: C ++ void "". - , - void , - .
, void -is-nothing void: , GNU, void*, char*, void*, , void , .
char*
, , : . void , .
, , , , , .
, . , , , "" , .
, , , , .
, , , .
(void)func1();
void x; x = func1();
void func2() { void x; ... return x; }
int func3(int x, void y, char z); void x = func3(1,2); x = func3(1,x,2);
, .
Source: https://habr.com/ru/post/1761492/More articles:Press enter key in qtp - vbscriptOpenCV: drawing an image - imageJUnit - website testing - javaCreating second shortcuts in Launcher - javaLINQ to SQL DAL, is this thread safe? - multithreadingSaving rootViewController? - objective-cWhat is the permission status based on Django Row? - djangoYahoo Pipes regex regexgoogle app engine: problem getting objects from data store in task - javaA regular expression that does not guarantee the repetition of a character is c #All Articles