簡體   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