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

7 Years
Discussion Span
Last Post by Stefano Mtangoo

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;
  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.

Edited by firstPerson: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.