| | |
Creating own datatypes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 19
Reputation:
Solved Threads: 0
You can create your own data type by either using a struct or by using a class.
And so you know....
If you need more help on this topic let us know
And so you know....
C++ Syntax (Toggle Plain Text)
//This is invalid sizeof(myowndatatype) = 3; //You can't assign a value to a function... //It should be this for seeing how big it is int size = 0; size = sizeof(myowndatatype);
If you need more help on this topic let us know
If you don't know it, learn it ;)
Greetings chound,
C provides typedef, a facility for creating new data type names. It makes your name a synonym of the defined data-type:
The type Number can be used in declarations and casts in exactly the same ways that the defined type int can be:
Using a synonym for "char *" is similarily declared. Example:
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.
Hope this helps,
- Stack Overflow
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; C++ Syntax (Toggle Plain Text)
Number i, cars; Number *blocks[];
Using a synonym for "char *" is similarily declared. Example:
typedef char *Str;
Str s, a[5], *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.
Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
C provides a compile-time unary operator called sizeof that can be used to compute the size of any object:
It is impossible to set data to a variable using the sizeof operator, as its only purpose is to tell you the size of your object. Using the following example may help get the size of your object.
Hope this helps,
- Stack Overflow
sizeof (type name)It is impossible to set data to a variable using the sizeof operator, as its only purpose is to tell you the size of your object. Using the following example may help get the size of your object.
typedef int Number; Number size; size = sizeof(Number);
Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Sep 2004
Posts: 19
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by chound
by sizeof(myowndatatype) = 3 I meant that the size of the datatype should be 3 bytes
If we know where you're coming from we might be able to better help you find a solution.
If you don't know it, learn it ;)
![]() |
Similar Threads
- Is it possible to create your very own data type? (C++)
- Java Datatypes to SQL Datatypes (Java)
- Creating and destroying objects (C++)
Other Threads in the C++ Forum
- Previous Thread: fstream.h, I thought it was a standard header....
- Next Thread: Error message help?
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





