473,473 Members | 4,208 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with g++

1 New Member
I am using Visual C++ and when I compile the following code there are no errors or warnings. However, when I compile with g++ I get 3 errors and 1 warning.

Here is the part of the code that generated the errors.
----------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. int divsum(int x, vector<int> y) //returns the sum of the PROPER divisors
  2. {
  3.     int t;
  4.     double sum=1;
  5.     int L=y.size();
  6.     for(t=0; t<L; t++) //go through each element of the list of generated primes
  7.     {
  8.         int e=1;
  9.         double psum=1;
  10.         if(x%y[t]==0)//test for divisibility
  11.         {
  12.             while(fmod(x,pow(y[t],e))==0) //sum of p^e where p^e divides y
  13.             {
  14.                 psum=(int) psum+pow(y[t],e);
  15.                 e++;
  16.             }
  17.             sum=sum*psum; //formula for divisor sum
  18.         }
  19.     }
  20.     int rsum; rsum= (int)sum;
  21.     return rsum-x;
  22. }
-------------------------------------------------------------------------------------------------------------
The error messages all read something similar to: "divisorsum.cpp:73: error: call of overloaded âpow(int&, int&)â is ambiguous"

What is the mistake, and how can I avoid making it in the future?
Nov 21 '07 #1
2 1720
Laharl
849 Recognized Expert Contributor
pow() is an old C function, which for some strange reason was never written to take two integer parameters or return an integer. You could write your own version, but the valid signatures for <cmath> pow() are:

double pow(double base, double exponent)
long double pow(long double base, long double exponent)
float pow(float base, float exponent)

You can use a cast to change your int into a double - not a static_cast<double> or anything similar (those are for real emergencies) - just a simple cast and then you could use floor() to return it to integer form. Since your doubles will be whole numbers in this problem, there is no issue.

Expand|Select|Wrap|Line Numbers
  1. int a = 4, b = 2;
  2. int c = floor(pow(double(4), double(2))); //c = 16
  3.  
Nov 21 '07 #2
Ganon11
3,652 Recognized Expert Specialist
Ah, so our mystery pow() problem seems to be g++ specific? Or, at least, Visual C++ has provided an int pow(int, int) function in their <cmath> header file.

Anyway, your warning is probably, "WARNING: no newline at end of file." I think this is a ridiculously silly warning, but you can get rid of it by entering your source code file, pressing Ctrl+End to go to the end of your file, pressing Enter/Return once, and saving.
Nov 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.