Calling all Dev_C++ users,

Here's a mystery! The following little program, which determines whether one integer is a divisor of another or not, compiles and runs fine using Borland's bcc32.

#include <iostream>
using namespace std;
bool divides(int,int);

main()
{     int a,b;
      char ch;
      cout << "Enter a then b: ";
      cin >>a>>b;
      if(divides(a,b))
        cout << a << " is a divisor of "<<b<<'\n';
      else
        cout << a << " isn't a divisor of  "<<b<<'\n';
	cin >> ch; //for dev-c++

}

bool divides(int b,int a)
{    if (!(a%b))
        return true;
     return false;
 }

When I try compiling it using Dev_C++ I get the message that there's a problem on line 9 because that's the first use of the function "divides". Apparently the compiler is ignoring the function prototype. Now comes the really strange part! If the function name is changed (all three times that it occurs) to almost anything I try, like "divideth" or "fct" or "product" the program works fine, but if I change it to "multiplies" I get the same compilation error.

Can anyone explain this phenomenon?

divides is a standard function object defined in <functional>, and Dev-C++ is better at not letting you do stupid things than the older Borland C++ 5.5 (which is what I assume you're using).

Borland C++ 5.4 (which ships with BCB4) and 5.5.1 both indeed allow it (both are 6-8 years old by now).
Don't have any others installed here at the moment (VC++ 2005 will go onto this machine in about 2 weeks).

You're indeed most likely getting namespace clashes. Remove the using namespace std; and replace it with explicit namespace references and that may well be gone.

BCC32 has divides in its includes, but it's a template struct taking 3 parameters instead of 2, thus making the function defined in this code sample distinct from the one in the standard library as BCC32 knows it.

Then again, I can't find a reference to <functional> in any of the header files called directly or indirectly by this sample in the headers as supplied by BCC32, so the compiler would never find a clash.

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.