function-overloading

    3熱度

    2回答

    如何爲c11 _通用函數添加額外的類型? 您是否需要#undef/re-#定義它?(如果是的話,下面的工作)還是有更好的方法? #define to_str(X) _Generic((X), \ long double: ld_str, \ double: d_str, \ float: f_str, \ )(X) #undef to_str #de

    3熱度

    1回答

    例如,GCC和鐺均不能編譯下面的代碼: struct S {}; namespace N { void g(S); } using N::g; namespace N { void g(int); } int main() { g(0); } 與錯誤: test.cpp: In function 'int main()': test.

    3熱度

    1回答

    我想寫一些類型列表的適配器代碼。下面是爲目的的實驗代碼: struct null { }; template<typename first, typename second> struct cell { typedef first head; typedef second tail; }; template < typename T1 = null,

    3熱度

    4回答

    可能重複: In C++ how is function overloading typically implemented? 我所經歷的布魯斯Eckel的書OOPS,其中指出關於工作有關重載函數如果它們在返回值和參數傳遞方面有差異。 int fun() :: could be represented as __int__fun float fun():: could be represente

    -2熱度

    2回答

    我試圖阻止類B訪問DoSomething(Y類)函數並且只訪問DoSomething(類X)。我如何用C++來做到這一點? Class A { public: void DoSomething(Class Y); } Class B: public A { public: void DoSomething(Class X); }

    2熱度

    3回答

    我有這樣的代碼: void Foo(int& a, string& b, vector<int>& c) { ... // 30 lines of code are same as another function ... // 10 lines of code to parse and assign value to vector<int>& c } void Foo(int& a,

    -1熱度

    1回答

    我有一個函數,其當前簽名是f(a,b = 0)。我想添加另一個參數c。我希望我的函數能夠以這種方式調用f(a,b),這是當前的行爲,f(a,c)。一種方法是重載函數並複製函數代碼。我不想從f(a,c)調用f(a,b)。我正在使用C++。 是否有任何標準設計模式或解決方案可以避免此代碼重複?

    0熱度

    1回答

    我在下面的函數中遇到了這個錯誤。有沒有人有一個想法是什麼意思? template <class T> void printAll(Array <T> &A){ for(int i=0; i<31; i++){ A.M[i].printObj; ///// ERROR std::cout<<std::endl; } } 函數應該打印所有的對象。 .

    0熱度

    2回答

    我有一個問題,我無法弄清楚。 使用這些類: PrimitiveToken GBVariable GBFloat: public class GBFloat extends GBVariable<Float> { public GBFloat(String name, Float value) { super(name, value); } } PLUSTOKEN: @Overrid

    0熱度

    2回答

    我正在考慮如何管理客戶端上的JavaScript行爲。 假設在我的HTML頁面,我頂... <script> var XMLHttpRequest = function() { this.send = function() { alert(args.toString()); } }; 是否有可能隨後(在同一頁面上)訪問本地XMLHttpRequest對象?