| | |
Is it possible to create your very own data type?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Greetings! So my question is: Is it possible to create your own data type? Not a class, or a structure, that builds from predefined C++ types, but your very own. For example a 128bit integer type, or a very very long floating point data type, or a binary number type to work with bit patterns. Something like these.
Also, I would like to know what is the smallest size you can address in C++, is it 1 byte or can you go further? Thank you very much.
Also, I would like to know what is the smallest size you can address in C++, is it 1 byte or can you go further? Thank you very much.
"Just because I'm losing, doesn't mean I'm lost. Doesn't mean I'll stop."
Thanks, but just to recap, my question is: Is it possible to create a data type which is not bounded to predefined C++ data types. I can create my own classes. but that would still rely on them. ( int, char, double whatever.. ). E.g.: what If I want to create a 6000 byte long number? ( I know, it would be insane, but just for the sake of curiosity.)
"Just because I'm losing, doesn't mean I'm lost. Doesn't mean I'll stop."
•
•
Join Date: May 2008
Posts: 538
Reputation:
Solved Threads: 86
If you don't intend to use any of the predefined C++ data types in your implementation, what do you propose to use?
A 6000 byte long number could be implemented, I would probably use an array with 6000 elements, but that still uses base C++ data types.
(Ignoring the fact that arbitrary precision math class is probably already available.)
I'd recommend getting over the "I don't want to use the ___, how do I do ___" mentality and focus on the objective of what you want to be done. Use the tools that are available.
If you don't have an objective that has been assigned, from school or work, then develop your own objective and assign it to yourself. This question appears to be argumentative on the surface. If you have a real-world situation that would make this line of inquiry make sense, feel free to present it.
A 6000 byte long number could be implemented, I would probably use an array with 6000 elements, but that still uses base C++ data types.
(Ignoring the fact that arbitrary precision math class is probably already available.)
I'd recommend getting over the "I don't want to use the ___, how do I do ___" mentality and focus on the objective of what you want to be done. Use the tools that are available.
If you don't have an objective that has been assigned, from school or work, then develop your own objective and assign it to yourself. This question appears to be argumentative on the surface. If you have a real-world situation that would make this line of inquiry make sense, feel free to present it.
•
•
•
•
Thanks, but just to recap, my question is: Is it possible to create a data type which is not bounded to predefined C++ data types. I can create my own classes. but that would still rely on them. ( int, char, double whatever.. ). E.g.: what If I want to create a 6000 byte long number? ( I know, it would be insane, but just for the sake of curiosity.)
In the future, please keep your insanity to yourself. The insanity isn't wanting a 6000 byte number, it's asking how to create datatypes when the mechanism for creating datatypes is staring you in the face.
I'm being mean. If you wanted to create a 6000 byte long number, you would do something like this:
C++ Syntax (Toggle Plain Text)
class int6000 { uint32_t data[1500]; public: // ... };
uint32_t is not a C++-standard type, I don't think, so substitute whatever 4-byte integer type you want if it doesn't work on your compiler (try #include <limits.h> to make uint32_t available).
Last edited by Rashakil Fol; Feb 21st, 2009 at 1:56 pm.
>Is it possible to create your own data type? Not a class, or a
>structure, that builds from predefined C++ types, but your very own.
What do you think a class is supposed to be? It's a user-defined type. What you seem to want is magic: a magic type that magically does something useful without any underlying logic. It doesn't work that way. There's no magic in programming. There's always a base that you build on top of to create something new. In the case of C++, you create new types by leveraging the power of existing types. I find your question to be misguided and nonsensical.
>Also, I would like to know what is the smallest size you can address in C++
char is the smallest addressable unit in C++.
>structure, that builds from predefined C++ types, but your very own.
What do you think a class is supposed to be? It's a user-defined type. What you seem to want is magic: a magic type that magically does something useful without any underlying logic. It doesn't work that way. There's no magic in programming. There's always a base that you build on top of to create something new. In the case of C++, you create new types by leveraging the power of existing types. I find your question to be misguided and nonsensical.
>Also, I would like to know what is the smallest size you can address in C++
char is the smallest addressable unit in C++.
I'm here to prove you wrong.
![]() |
Similar Threads
- hyperlink data type? (MySQL)
- MS SQL data type length (MS SQL)
- Combined data type arrays. (C++)
- C++ Data Types (C++)
- Working with SQL's Text data type (ASP.NET)
- accessing private data members (C++)
- Text data type troubles in T-SQL (Database Design)
- Create Windows Authentication (VB.NET)
- Pi Approximation (C++)
Other Threads in the C++ Forum
- Previous Thread: linked list - converted to stack using linked list
- Next Thread: help with file
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






