Search code examples
c++double

Diffrence between real and double


double real2double(real* r) //This function job is to transform real objects to double
{
    double n = r->num;
    double frac = r->frac; //Saving the number
    while (frac > 1) //Saving the fraction
        frac =frac/10;
    n =n+frac;
    return n;
}

I found this function to convert real to double in C++ I'm quite new to this and wonder what is the diffrence between real and double.. why should I even bother converting from one to another


Solution

  • In your code real appears to be a class type. From the usage in the function we can conclude that it has members frac and num of some type that either is double or can be converted to double. The members are accessible in the function which implies they are either public or the function is a friend of the class. Making not more assumptions than that, we would expect some definition along the line of:

    struct real {
        double frac;
        double num;
    };
    

    what is the diffrence between real and double..

    real is a user defined type. double is one of C++s fundamental types.