How do we create datatypes in C++. Eg. creating datatype called "myowndatatype" with sizeof(myowndatatype) = 3
2 Months Ago
Related Article:Creating binary matrix in openCV
is a solved C++ discussion thread by nyquist that has 2 replies, was last updated 7 months ago and has been tagged with the keywords: opencv, matrix, binary.
C provides typedef, a facility for creating new data type names. It makes your name a synonym of the defined data-type:
typedef int Number;
The type Number can be used in declarations and casts in exactly the same ways that the defined type int can be:
Number i, cars;
Using a synonym for "char *" is similarily declared. Example:
typedef char *Str;
Str s, a, *p;
The type being declared in a typedef appears in the position of a variable name, not after the word typedef. The typdef sytax is like the storage classes extern, static, and many others. The typedef declaration does not create a new data-type of any sense. It's simply stated as it adds a new name for some existing type.
typedef is similar to #define, expect that it is interpreted by the compiler. There aren't any new semantics. Variables declared this way have exactly the same properties as variables whose declarations are spelled out explicitly.
Ok so i have a question... This is crazy i know but just hear me out.
Ive been trying to learn of how to create datatypes etc. ive also been interested in how microsoft sets up their data types, for instance, do they just set it up with crazy amounts of 'if' statements or is it billions of set values that you can only enter but ive found nothing... anyways to the point sorry. . . Ive been trying to learn how the identifiers like 'long' 'short' 'unsigned' etc work where they go in front of a data type and modify it. The reason for this is ive been wanting to create my own data type "super" that will be placed before a "bool" and modify it in the sense where instead of only 2 values (true/false) i wish to add a third "unknown". I use bools a lot and i wish it had a third value for invalid entries or if the answer to it is truely "unknown" and well its not out there. I know i could just simply set up an int variable and just check if1=true if2=false if3=unknown but i want to go into this field and i would like to know some of the inner workings and not just the long "typical" way to go about it where any beginner could do it (if you know what i mean). If you could help me out that would be awesome thanks!