new-operator

    -1熱度

    2回答

    如果有人可以解釋這兩種類型的數組初始化的,將是巨大的區別: 有一個在ListReturn類的靜態方法getList(),這在調用返回ArrayList<Some_Custom_Object>。 在調用類的,我可以調用函數有兩種方式如下:這裏 List<Some_Custom_Object> listFromCall = new ArrayList<Some_Custom_Object>(); li

    1熱度

    1回答

    的論cppreference現場,我看到下面的句子: 這是C++保留關鍵字的列表。因爲它們被使用的語言,這些關鍵字不可供重新定義或超載。 其中有新。但我知道我們可以在C++中重載新的。 所以上面的引文是錯誤的或有別的東西出現的關鍵字新?

    4熱度

    6回答

    我正在學習C++,我知道'新'關鍵字用於將內存中的地址分配給指針。而且我認爲使用'nullptr'時會初始化一個指向無效的指針。那是對的嗎?參考實例: //using nullptr int *x = nullptr; //this is just a pointer that points to nothing and //will need to be initialize

    0熱度

    2回答

    #include <QCoreApplication> #include <stdio.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); FILE *fp; fp = new FILE [2]; fp[0] = fopen ("temp.txt", "w")

    1熱度

    2回答

    我想寫我自己的Allocator可以在STL中使用。這遠我幾乎可以順利完成,但有一個功能,我有我的問題: 的Allocator在STL使用應[使用new & delete標準分配示例]提供的功能construct: // initialize elements of allocated storage p with value value void construct (T* p, const

    4熱度

    1回答

    我正在C++編寫我自己的內存系統(出於性能原因,附加的調試信息以及我可以分配16字節對齊的內存)和I我遇到了新問題[]。 看來,調用new []會導致分配額外的4個字節,表示數組中元素的數量,這會拋出所有後續對象的對齊。所以我的問題是:有沒有辦法通過編譯器標誌,雜注聲明等來關閉這4個額外字節的使用? 下面是一個例子: // Matrix class has to be 16-byte aligne

    0熱度

    2回答

    由於某種原因,我的實現允許0大小的數組訪問0位置和5大小的數組訪問50個位置。雖然這兩個職位都必須爲我提供一個分段錯誤的錯誤。我認爲這可能是由錯誤地分配內存引起的,但在我看來它看起來是正確的,有人可以告訴我爲什麼我獲得了這個結果。 我的數組代碼: class vector{ private: int length; int cap; T* arr; public:

    -2熱度

    3回答

    我需要從調用class T的常規構造如下禁止用戶: T obj (a, b, c); // Compile-time error T* objPtr = new T (a, b, c); // OK 是否有可能在C++?

    -1熱度

    1回答

    的MWE是 #include <iostream> using namespace std; class N { public: float x; N() { x = 0.0; } N(float a) { x = a; } //N(N &n) { x = n.x; } N &operator=(float f) { cout << "#

    0熱度

    2回答

    有沒有辦法知道指針變量的內存是使用new還是malloc分配的? int* a = new int; int* b = static_cast<int*>(malloc(sizeof *b)); //Maybe using a function? allocatedwithnew(a); //Returns true allocatedwithmalloc(b); //Return tr