how would i make a new type of variable, like instead of int or double? would i use classes or something like that?
how would i make a new type of variable, like instead of int or double? would i use classes or something like that?
From my own painfully limited experience, I believe you are looking for a struct. A struct allows you to create a new type, made up of combinations of the essential data types, which can then be treated like a data type.
Yes. Classes is one way. For example here is a simple Type.
class Int{
int val;
public:
Int() {val = 0;}
Int(const int& initVal) { val = initVal; }
/* more functions */
};
You could make it just like a int variable, but it has its difference. Similarly, you can Imagine
a class called say, Fraction{ ... } that acts like a fraction, but internally holds a numerator and an
denominator, both type int. But you treat the Fraction class like its a regular data type. So you might multiply
it to another fraction, or add and so on.
typedef int IntegerByMe;
it defines alias for integer.
Is that what you ask or I have misunderstood you?