Polyamorphic functions and compiler errors

Book I'm working from had me input a polymorphic function code. Got it in word for word, but I'm getting compiler errors. I'm not sure what's causing the errors, b/c I copied it verbatim. Thinking it may be a compiler issue...?

1
2
3
In function 'long intDoulbe(long int)':
new declaration 'long int Doulbe(long int)'
ambiguates old declaration 'int Double(long it)'


So, that's the error. I get it for the functions float Double(float), long Double(long) and double Double(double). I know, horrible naming, but I'm copying out of the book...

Here's the code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;

int Double(int);
int Double(long);
int Double(float);
int Double(double);

int main()
{
    int            myInt = 6500;
    long           myLong = 65000;
    float          myFloat = 6.5F;
    double         myDouble = 6.5e20;
    
    int            doubledInt;
    long           doubledLong;
    float          doubledFloat;
    double         doubledDouble;;
    
    cout << "myInt:\t " << myInt << endl;
    cout << "myLong:\t " << myLong << endl;
    cout << "myFloat:\t " << myFloat << endl;
    cout << "myDouble:\t " << myDouble << endl;
    
    doubledInt = Double(myInt);
    doubledLong = Double(myLong);
    doubledFloat = Double(myFloat);
    doubledDouble = Double(myDouble);
    
    cout << "doubledInt:\t " << doubledInt << endl;
    cout << "doubledLong:\t " << doubledLong << endl;
    cout << "doubledFloat:\t " << doubledFloat << endl;
    cout << "doubledDouble:\t " << doubledDouble << endl;
    
    system("pause");
}

int Double(int original)
{
    cout << "In Double(int)\n";
    return 2 * original;
}

long Double(long original)
{
     cout << "In Double(long)\n";
     return 2 * original;
}
     
float Double(float original)
{
      cout << "In Double(float)\n";
      return 2 * original;
      }
      
double Double(double original)
{
       cout << "In Double(double)\n";
       return 2 * original;
       }
       


The compiler I'm using is Dev C++ v4.9.9.2

I may be trying out Visual shortly, if you can think of any pros to that compiler vs. Dev, I'd like to know. Thanks!
declarations vs definitions, find the difference:
1
2
3
4
int Double(int);
int Double(long);
int Double(float);
int Double(double);
int Double(int);
long Double(long);
float Double(float);
idouble nt Double(double);

The compiler I'm using is Dev C++ v4.9.9.2
Stop using it right now. Like, select directory with it and press shift+delete.

It is terribly outdated, contains numerous bugs and does not eve support C++11 standard. If you want to continue using it, switch to Orwell Dev-C++ 5.6.3.
Topic archived. No new replies allowed.