有可能與C++做下面的代碼:可以在C++中爲函數內的數組分配一個Int值?
myFunction(myArray, positionInsideMyArray) = myValue.
cout << myFunction[positionInsideMyArray] << endl; // Display muValue
我如何能做到這一點與C++?
爲了讓我的問題更清楚,使用一個值以下代碼可以正常工作, 我想要做同樣的事情,但使用Array參數。
int& myFunction(int &x){
return x;
}
這是主要的功能:
int x;
myFunction(x) = myValue;
cout << x << endl; // This will display myValue
您可以在C++中使用重載的運算符函數執行各種瘋狂的事情。你需要爲你的問題提供更多的上下文。請發佈[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –
是的。你可以用C++做所有這些事情,使用'operator()'重載和'operator []'重載。 – Mykola
@Yacino只需搜索「C++將數組傳遞給函數」。 – LogicStuff