第一个正式的参数是'运算符new'必须是'size_t'

时间:2021-10-24 09:30:11

i am getting this error "first formal parameter to 'operator new' must be 'size_t'" when i try to compile smth like this:

当我尝试编译smth的时候,我将会将这个错误“第一个正式的参数”变成“new”。

void* operator new(MyStd::UInt);

I use visual studio 2013 express running on a 64 bit machine.

我使用visual studio 2013 express在64位机器上运行。

Does anyone know, why this error occurs?

有人知道为什么会出现这种错误吗?

If you need further information, pls let me know...this project is huge!

如果您需要进一步的信息,请告诉我……这个项目是巨大的!

3 个解决方案

#1


3  

Exactly what the error message says: the first parameter must be of type size_t.

错误消息的确切含义是:第一个参数必须是类型size_t。

That is exactly what the reference suggests.

这正是参考所建议的。

#2


2  

The error says it all. First parameter of operator new must be of type std::size_t and you use some other type.

错误说明了一切。操作符new的第一个参数必须是std::size_t,然后使用其他类型。

#3


0  

Except that it can't, really, since std::size_t is a typedef; it must have whatever type std::size_t is typedef'ed to. The easiest way of getting this is to declare it as std::size_t. Re: it worked in the past: presumably, in the past, MyStd::UInt was a typedef to the same type as std::size_t. Now, one or the other typedef has changed. Just declare the first parameter of operator new to be size_t, and it will automatically be the right type; declare it anything else, and you're guessing how std::size_t is declared (which can change from one implementation to another, or even from one version to another).

除了它不能,真的,因为std::size_t是一个typedef;它必须有任何类型的std::size_t是类型定义的。最简单的方法是将它声明为std::size_t。Re:它在过去工作过:假设在过去,MyStd::UInt是与std::size_t相同类型的类型定义。现在,一个或另一个typedef已经发生了变化。只需声明new的第一个参数为size_t,它将自动为正确的类型;声明它的任何其他内容,并且您猜测std::size_t被声明(它可以从一个实现更改为另一个实现,甚至从一个版本更改到另一个实现)。

#1


3  

Exactly what the error message says: the first parameter must be of type size_t.

错误消息的确切含义是:第一个参数必须是类型size_t。

That is exactly what the reference suggests.

这正是参考所建议的。

#2


2  

The error says it all. First parameter of operator new must be of type std::size_t and you use some other type.

错误说明了一切。操作符new的第一个参数必须是std::size_t,然后使用其他类型。

#3


0  

Except that it can't, really, since std::size_t is a typedef; it must have whatever type std::size_t is typedef'ed to. The easiest way of getting this is to declare it as std::size_t. Re: it worked in the past: presumably, in the past, MyStd::UInt was a typedef to the same type as std::size_t. Now, one or the other typedef has changed. Just declare the first parameter of operator new to be size_t, and it will automatically be the right type; declare it anything else, and you're guessing how std::size_t is declared (which can change from one implementation to another, or even from one version to another).

除了它不能,真的,因为std::size_t是一个typedef;它必须有任何类型的std::size_t是类型定义的。最简单的方法是将它声明为std::size_t。Re:它在过去工作过:假设在过去,MyStd::UInt是与std::size_t相同类型的类型定义。现在,一个或另一个typedef已经发生了变化。只需声明new的第一个参数为size_t,它将自动为正确的类型;声明它的任何其他内容,并且您猜测std::size_t被声明(它可以从一个实现更改为另一个实现,甚至从一个版本更改到另一个实现)。