繁体   English   中英

gcast类型转换后找不到重载函数

[英]g++ cannot find the overloaded function after typecast

我有一个重载的功能

void FuncGetSomething(string, double&)
void FuncGetSomething(string, int&)
void FuncGetSomething(string, bool&)

....应该以这种方式工作

double myDbl = 0;
FuncGetSomething("Somename", myDbl) 
//to get the new value for myDbl in side the function, and the new value is preset earlier in the code

但是由于某种原因,我看到有人写了这个

double myDlb = 0;
FuncGetSomething("Somename", (double)myDbl)

这可以在Visual Studio 2008中使用。

但是,当我尝试在Linux(g ++ 4.7.2)中构建相同的东西时,它抱怨

error: no matching function for call to  GetSomething(const char [8], double) can be found

谁能给我一些关于为什么它可以在VS08中运行的想法,以及为什么它不能在Linux中运行? 无论如何,它也可以在Linux中工作吗?

强制转换为(double)表示正在创建double类型的临时对象。 调用该函数时,您试图将非常量引用绑定到该函数,这是不允许的。 这可能会有所帮助:

void f( double& ) {};

double d = 1.2;
f( d ); // allowed (1)
f( 1.2 ); // not allowed (2)
f( (double)d ); // not allowed, basically the same as (2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM