A question on overloaded function? Can anyone with kindness help me?
I use Dev-C++,and the snipet of the program is: #pragma hdrstop # include <iostream> # include <vector> # include <iterator> # include "boost/math/common_factor.hpp" # include "boost/lambda/lambda.hpp" # include "boost/lambda/bind.hpp" # include "boost/lambda/if.hpp" # include "boost/lambda/casts.hpp" # include "boost/lambda/construct.hpp" # include "boost/lambda/loops.hpp" # include "boost/lambda/switch.hpp" # include "boost/tuple/tuple.hpp" # include "boost/tuple/tuple_comparison.hpp" # include <string> # include <map> using namespace std; using namespace boost::lambda; using namespace boost; void a(){ std::cout<<std::pow(4,3); return; } ............... but the complier told me that: main2test.cpp: In function `void a()': main2test.cpp:69: call of overloaded `pow(int, int)' is ambiguous F:/CB2009/Dev-Cpp/include/math.h:162: candidates are: double pow(double, double) F:/CB2009/Dev-Cpp/include/c++/cmath:401: float std::pow(float, float) F:/CB2009/Dev-Cpp/include/c++/cmath:410: long double std::pow(long double, long double) F:/CB2009/Dev-Cpp/include/c++/cmath:419: double std::pow(double, int) F:/CB2009/Dev-Cpp/include/c++/cmath:423: float std::pow(float, int) F:/CB2009/Dev-Cpp/include/c++/cmath:427: long double std::pow(long double, int) And in my computer, the C++ libraries includes are F:\CB2009\Dev-Cpp\include\c++ F:\CB2009\Dev-Cpp\include\c++\mingw32 F:\CB2009\Dev-Cpp\include\c++\backward F:\CB2009\Dev-Cpp\include F:\CB2009\boost_1_34_1\boost_1_34_1 I do not know how to solve it.I do not use <math> or <cmath> yet. Why the complier told me such files? And whether the two files are included in other files or not? And can I use: bind(&std::pow,constant(-1),bind(&IIPrimemap::size,var(primemapvec))); in the program? where : typedef std::pair<int, int> IIPrimepair; std::vector<IIPrimepair> primepairvec; Can anyone with kindness help me?
AMDG fmingu wrote:
I use Dev-C++,and the snipet of the program is: #pragma hdrstop # include <iostream> # include <vector> # include <iterator> # include "boost/math/common_factor.hpp" # include "boost/lambda/lambda.hpp" # include "boost/lambda/bind.hpp" # include "boost/lambda/if.hpp" # include "boost/lambda/casts.hpp" # include "boost/lambda/construct.hpp" # include "boost/lambda/loops.hpp" # include "boost/lambda/switch.hpp" # include "boost/tuple/tuple.hpp" # include "boost/tuple/tuple_comparison.hpp" # include <string> # include <map>
using namespace std; using namespace boost::lambda; using namespace boost;
void a(){ std::cout<<std::pow(4,3); return; } ............... but the complier told me that:
main2test.cpp: In function `void a()': main2test.cpp:69: call of overloaded `pow(int, int)' is ambiguous F:/CB2009/Dev-Cpp/include/math.h:162: candidates are: double pow(double, double) F:/CB2009/Dev-Cpp/include/c++/cmath:401: float std::pow(float, float) F:/CB2009/Dev-Cpp/include/c++/cmath:410: long double std::pow(long double, long double) F:/CB2009/Dev-Cpp/include/c++/cmath:419: double std::pow(double, int) F:/CB2009/Dev-Cpp/include/c++/cmath:423: float std::pow(float, int) F:/CB2009/Dev-Cpp/include/c++/cmath:427: long double std::pow(long double, int)
And in my computer, the C++ libraries includes are F:\CB2009\Dev-Cpp\include\c++ F:\CB2009\Dev-Cpp\include\c++\mingw32 F:\CB2009\Dev-Cpp\include\c++\backward F:\CB2009\Dev-Cpp\include F:\CB2009\boost_1_34_1\boost_1_34_1 I do not know how to solve it.
There is no overload of std::pow that takes two ints. You need to match one of the possible signatures exactly.
I do not use <math> or <cmath> yet. Why the complier told me such files? And whether the two files are included in other files or not?
Apparently cmath is included indirectly by some other header file. This is hardly an unusual occurrence in C++...
And can I use: bind(&std::pow,constant(-1),bind(&IIPrimemap::size,var(primemapvec)));
You can't pass the address of an overloaded function to a function template like bind without casting it to the correct function pointer type.
in the program? where : typedef std::pair<int, int> IIPrimepair; std::vector<IIPrimepair> primepairvec;
Can anyone with kindness help me?
In Christ, Steven Watanabe
But how can I change the expression to be legal and usable? bind(&std::pow,constant(-1),bind(&IIPrimemap::size,var(primemapvec))); I tried : bind(&std::pow,constant(-1.0),bind<int>(&IIPrimemap::size,var(primemapvec))); and bind(&std::pow,constant(-1.0),ret<int>(bind(&IIPrimemap::size,var(primemapvec)))); even bind(&std::pow,constant(-1.0),ll_dynamic_cast<int>(bind(&IIPrimemap::size,var(primemapvec)))); But the complier told me that: cannot resolve overloaded function `pow' based on conversion to type `unsigned int' I do not know how to solve now. Can anyone with kindness help me? 在2009-07-01,"Steven Watanabe" <watanabesj@gmail.com> 写道:
AMDG
fmingu wrote:
I use Dev-C++,and the snipet of the program is: #pragma hdrstop # include <iostream> # include <vector> # include <iterator> # include "boost/math/common_factor.hpp" # include "boost/lambda/lambda.hpp" # include "boost/lambda/bind.hpp" # include "boost/lambda/if.hpp" # include "boost/lambda/casts.hpp" # include "boost/lambda/construct.hpp" # include "boost/lambda/loops.hpp" # include "boost/lambda/switch.hpp" # include "boost/tuple/tuple.hpp" # include "boost/tuple/tuple_comparison.hpp" # include <string> # include <map>
using namespace std; using namespace boost::lambda; using namespace boost;
void a(){ std::cout<<std::pow(4,3); return; } ............... but the complier told me that:
main2test.cpp: In function `void a()': main2test.cpp:69: call of overloaded `pow(int, int)' is ambiguous F:/CB2009/Dev-Cpp/include/math.h:162: candidates are: double pow(double, double) F:/CB2009/Dev-Cpp/include/c++/cmath:401: float std::pow(float, float) F:/CB2009/Dev-Cpp/include/c++/cmath:410: long double std::pow(long double, long double) F:/CB2009/Dev-Cpp/include/c++/cmath:419: double std::pow(double, int) F:/CB2009/Dev-Cpp/include/c++/cmath:423: float std::pow(float, int) F:/CB2009/Dev-Cpp/include/c++/cmath:427: long double std::pow(long double, int)
And in my computer, the C++ libraries includes are F:\CB2009\Dev-Cpp\include\c++ F:\CB2009\Dev-Cpp\include\c++\mingw32 F:\CB2009\Dev-Cpp\include\c++\backward F:\CB2009\Dev-Cpp\include F:\CB2009\boost_1_34_1\boost_1_34_1 I do not know how to solve it.
There is no overload of std::pow that takes two ints. You need to match one of the possible signatures exactly.
I do not use <math> or <cmath> yet. Why the complier told me such files? And whether the two files are included in other files or not?
Apparently cmath is included indirectly by some other header file. This is hardly an unusual occurrence in C++...
And can I use: bind(&std::pow,constant(-1),bind(&IIPrimemap::size,var(primemapvec)));
You can't pass the address of an overloaded function to a function template like bind without casting it to the correct function pointer type.
in the program? where : typedef std::pair<int, int> IIPrimepair; std::vector<IIPrimepair> primepairvec;
Can anyone with kindness help me?
In Christ, Steven Watanabe
AMDG fmingu wrote:
But how can I change the expression to be legal and usable? bind(&std::pow,constant(-1),bind(&IIPrimemap::size,var(primemapvec))); I tried : bind(&std::pow,constant(-1.0),bind<int>(&IIPrimemap::size,var(primemapvec))); and bind(&std::pow,constant(-1.0),ret<int>(bind(&IIPrimemap::size,var(primemapvec)))); even bind(&std::pow,constant(-1.0),ll_dynamic_cast<int>(bind(&IIPrimemap::size,var(primemapvec)))); But the complier told me that: cannot resolve overloaded function `pow' based on conversion to type `unsigned int'
Ignore the "conversion to unsigned int" part. The compiler doesn't know how to handle std::pow and gets itself confused. The problem is &std::pow, not the inner bind expression.
I do not know how to solve now. Can anyone with kindness help me?
You can't pass the address of an overloaded function to a function template like bind without casting it to the correct function pointer type.
In Christ, Steven Watanabe
Hi, On 6/30/09, fmingu <fmingu@163.com> wrote:
I use Dev-C++,and the snipet of the program is: ............ using namespace std; using namespace boost::lambda; using namespace boost;
void a(){ std::cout<<std::pow(4,3); return; }
I am not an expert but always try to use the using directives "using namespace xxx" as locally as possible. You could have used the using directives inside the function a() inside of dumping all of the namespaces globally. Moreover, may be you can do with std::pow ( 4.0, 3.0 ) to let the compiler see clearly that you are interested in the "double, double" version of pow() instead of the one based on integer arguments. In addition, may be you can enclose your relevant code inside your own namespace then you can typedef the specific overloaded version of the std::pow() function in your namespace to let the compiler resolve pow() call in your favor - to the locally declared pow() in your namespace instead of the other ones in std namespace. Alternatively, you declare and typedef a local pointer to the specific std::pow function in your code and then pass that pointer instead to the function you are interested in calling. -Asif
participants (3)
-
Asif Lodhi
-
fmingu
-
Steven Watanabe