•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,707 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,979 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 1156 | Replies: 2
![]() |
•
•
Join Date: Dec 2004
Location: Allentown, PA
Posts: 60
Reputation:
Rep Power: 4
Solved Threads: 1
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.
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?
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).
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation:
Rep Power: 18
Solved Threads: 195
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.
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.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Create Access Database using SQL queries (MS Access and FileMaker Pro)
- function style cast question (C++)
- Name of current function.. (Perl)
- what to use to create mobile phone menu?? (Computer Science and Software Design)
- Old School Compiler vs New Compiler (C++)
- QuickSort (Computer Science and Software Design)
Other Threads in the C++ Forum
- Previous Thread: Trying to use c++ to print to a usb printer
- Next Thread: Solution for Ex.4-5 in Acc.C++?



Linear Mode