nullptr

    3熱度

    2回答

    在我的課程中,我正在檢查值是否爲0以返回nullptr,但我似乎無法做到這一點。 Complex Complex::sqrt(const Complex& cmplx) { if(cmplx._imag == 0) return nullptr; return Complex(); } 我得到的錯誤是:could not convert 'nullptr'

    3熱度

    2回答

    在Visual Studio 2012年,我與指針瞎搞,我意識到,這個計劃一直崩潰: #include <iostream> using std::cout; using std::endl; int main() { const char* pointer = nullptr; cout << "This is the va

    0熱度

    1回答

    爲了好玩,我決定嘗試製作一個簡單的實體組件系統。我有一個包含所有組件的列表,並且我創建了一個名爲getPositionComponent的函數,它接受實體ID並返回與該實體相關的位置組件。我所做的所有組件都是從Components類派生的。 struct Component { public: std::string readableName; Component::Com

    3熱度

    4回答

    我使用C++進行編碼,並使用C函數在失敗的情況下返回NULL。將正確的想法做什麼,將其返回值與NULL或nullptr進行比較? if ((CreateEventEx(myEventHandleHere) == NULL) { ... } 或 if ((CreateEventEx(myEventHandleHere) == nullptr) { ... }

    1熱度

    1回答

    我一直在尋找在emulated version of nullptr見到了這個轉換操作符(nullptr_t的成員): template<class C, class T> // or any type of null operator T C::*() const // member pointer... { return 0; } 這句法成員函數指針混淆了我。我通常期望看到這樣的類型

    6熱度

    1回答

    我想知道是否有任何方法來檢查您分配到std::function的函數指針是否爲nullptr。我期待!操作員這樣做,但它似乎只有在函數被分配了nullptr_t類型的東西時才起作用。 typedef int (* initModuleProc)(int); initModuleProc pProc = nullptr; std::function<int (int)> m_pInit;

    10熱度

    2回答

    我遇到以下情況。在nullptr上進行移動有什麼優勢嗎?我假設它基本上給Node分配一個零,所以我不確定是否有優勢可以在這裏做一個移動。有什麼想法嗎? template <typename T> struct Node { Node(const T& t): data(t), next(std::move(nullptr)) { } Node(T&& t): data(st

    0熱度

    1回答

    我有以下幾點: void func(const char *p) { std::cout << p << "\n"; } void func(std::nullptr_t p) { std::cout << "<null>\n"; } int main() { func("test"); char *p=nullptr; func(p); func(

    6熱度

    3回答

    我已經看到了類似的文章圍繞這個,但不能讓Netbeans停止顯示錯誤信息"Unable to resolve identifier nullptr"當我的代碼工作正常。我正確地啓用了C++ 11,不確定問題是什麼?

    1熱度

    1回答

    我想知道關於參數傳遞nullptr的C++ 11最佳實踐。我想通過將nullptr傳遞給已有的setter函數來重置類成員對象。舉個簡單的例子: #include "foo.h" Foo my_foo; void set_foo(std::shared_ptr<Foo> bar){ my_foo = bar; } int main() { set_foo(std