how would i make a new type of variable, like instead of int or double? would i use classes or something like that?

Recommended Answers

All 3 Replies

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.