Code::blocks compiling issue: error: call of overloaded `pow(int, int)' is ambiguous|

Hi Guys,

I am trying to solve euler problem 184 for 2 weeks now. I was fisrt started to develop the code on DevC++, it was fine no errors I got. Then I switched it to Code::Blocks due to some linker messy issues of DevC++. Code:Blocks was fine but in this code below(which I was perfectly compiled in DevC++) it throws some errors like this:
C:\Users\Samsung\Desktop\C projects\Euler\Euler184\Eulrt_Test_V5\Euler184_Test_V5.cpp|45|error: call of overloaded `pow(int, int)' is ambiguous|

I will give the specific part of the code below. What do you think the problem might be? Thanks.


1
2
3
4
if( (int)( pow( (orj - j) , 2 ) + 0.5 ) + (int)( pow( (orj - i) , 2 ) + 0.5 )  < (int)( pow( r , 2 ) + 0.5 ) )
{
    //some stuff
}

Last edited on
C's pow is in the global scope, whereas C++'s std::pow isn't. This is one of the reasons why using namespace std; is bad - you make it impossible for the compiler to know which one you want.

Don't write using namespace std; and just use std::pow.
Last edited on
@LB, thank you man.

I did not know that std library has a pow method.

I made the change and the error is gone now. But new error came up: C:\Users\Samsung\Desktop\C projects\Euler\Euler184\Eulrt_Test_V5\Euler184_Test_V5.cpp|52|error: expected primary-expression before '{' token|

in the line:

1
2
3
4
5
6
7
if( (i < orj) && (j < orj) )
				{
					//
					chamberMatrix.push_back({1, j, i});
					stateOneMatrix.push_back({1, j, i});

				}
What is the type of chamberMatrix? Are you compiling with C++11 enabled?
type is int, and I use latest Code::blocks version. I am gonna research how to change compiler version. It is much more complex than Devc++
You cannot push multiple values into a vector that way, you have to call push_back multiple times.
1
2
3
4
5
6
7
8
9
std::vector<std::vector<int> > chamberMatrix;
std::vector<std::vector<int> > stateOneMatrix;
std::vector<std::vector<int> > stateTwoMatrix;
std::vector<std::vector<int> > stateThreeMatrix;
std::vector<std::vector<int> > stateFourMatrix;
std::vector<std::vector<int> > stateFiveMatrix;
std::vector<std::vector<int> > stateSixMatrix;
std::vector<std::vector<int> > stateSevenMatrix;
std::vector<std::vector<int> > stateEightMatrix;


No man, The vectors are muldimensional. Nothing wrong with the use of the method
Last edited on
Sorry, I misunderstood since you said the type was int and you actually meant it was vector of int.

To use that syntax you need to have C++11/C++14 enabled, usually done by passing a compiler flag -std=c++14
How would we know that since you did not show the declaration of them?
Topic archived. No new replies allowed.