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