删除操作符私有时获取错误 [英] Getting error while making delete operator private

查看:70
本文介绍了删除操作符私有时获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我试图让删除操作符为我的班级私有。奇怪的是,如果我在VC ++ .NET中编译该代码,则会给出错误

。但它在VC ++ 6.o上成功编译了

。任何人都可以给我关于它的意见。我想

在我的班级删除不应该工作。对象指针应该是

只使用我的函数删除,它正在处理引用计数

特定类。


Thanx in提前输入。


问候,

Premal Panchal

解决方案

" Premal" < pr *********** @ gmail.comwrote in message

news:11 ******************* ***@o61g2000hsh.googlegr oups.com ...





我试图将删除操作符设为私有为了我的课。奇怪的是,如果我在VC ++ .NET中编译该代码,则会给出错误

。但它在VC ++ 6.o上成功编译了

。任何人都可以给我关于它的意见。我想

在我的班级删除不应该工作。对象指针应该是

只使用我的函数删除,它正在处理引用计数

特定类。


Thanx in提前输入。



请显示您尝试过的无效工作。


8月13日,3:24下午,Jim Langston < tazmas ... @ rocketmail.comwrote:


" Premal" < premalpanc ... @ gmail.com写信息


新闻:11 ********************** @ o61g2000hsh.googlegr oups.com ...




我试过将删除操作符设为我的类私有。奇怪的是,如果我在VC ++ .NET中编译该代码,则会给出错误

。但它在VC ++ 6.o上成功编译了

。任何人都可以给我关于它的意见。我想

在我的班级删除不应该工作。对象指针应该是

只使用我的函数删除,这是为了处理引用计数
特定类的


提前填写您的输入。



请显示您尝试过的无效工作。





我试过以下一个:


class RefCountImpl

{

private:

//数据成员

受保护:

void operator delete(void * );

public:

//方法

};

如果我有上面的类实现。那么VC ++ 6.0它的工作原理。您可以使用new来分配内存,但不能删除

clilent代码中的指针。你必须使用上面提供的一些方法来释放指针。


同样的事情在VC ++ .NET中不起作用。它显然会抛出错误,使得删除私有导致内存泄漏。可能是VC ++ .NET编译器

变得更加激动人心。 :(.....


我希望你明白我的观点。我希望你能给我一些宝贵的意见。


问候,

Premal Panchal





我试过以下一个:


class RefCountImpl

{

private:

// data成员

受保护:

void operator delete(void *);

public:

// methods

};

如果我有上面的类实现。那么在VC ++ 6.0中它可以工作。你可以

使用new分配内存但是你不能删除你的

clilent代码中的指针。你必须使用上面提到的一些方法来释放指针。


同样的事情在VC ++ .NET中也不起作用。它显然会抛出错误,使得删除私有导致内存泄漏。可能是VC ++ .NET编译器

变得更加激动人心。 :(.....



首先,这不是删除操作符(尽管它很不幸

名称)它是内存释放功能。编译器可以自由地发出他们想要的任何诊断信息。


你为什么要这样做?


Hi,

I tried to make delete operator private for my class. Strangely it is
giving me error if I compile that code in VC++.NET. But it compiles
successfully on VC++6.o. Can anybody give me inputs about it. I wanted
that on my class delete should not work. Object pointer should be
deleted using my function only which is taking care of reference count
for particular class.

Thanx in advance for your inputs.

Regards,
Premal Panchal

解决方案

"Premal" <pr***********@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...

Hi,

I tried to make delete operator private for my class. Strangely it is
giving me error if I compile that code in VC++.NET. But it compiles
successfully on VC++6.o. Can anybody give me inputs about it. I wanted
that on my class delete should not work. Object pointer should be
deleted using my function only which is taking care of reference count
for particular class.

Thanx in advance for your inputs.

Please show what you tried that didn''t work.


On Aug 13, 3:24 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:

"Premal" <premalpanc...@gmail.comwrote in message

news:11**********************@o61g2000hsh.googlegr oups.com...

Hi,

I tried to make delete operator private for my class. Strangely it is
giving me error if I compile that code in VC++.NET. But it compiles
successfully on VC++6.o. Can anybody give me inputs about it. I wanted
that on my class delete should not work. Object pointer should be
deleted using my function only which is taking care of reference count
for particular class.

Thanx in advance for your inputs.


Please show what you tried that didn''t work.

Hi,
I tried following one:

class RefCountImpl
{
private:
//data members
protected:
void operator delete(void*);
public:
//methods
};
if i have above class implementation.Then in VC++6.0 it works. You can
allocate memory using new but you cannot delete that pointer in your
clilent code. You have to use some method provided by above class to
release the pointer.

Same thing doesnt work in VC++.NET. It clearly throws error that
making delete private cause memory leakage. May be VC++.NET compiler
become more stirct about this. :(.....

I hope you got my point. I hope you can give me some valuable input.

Regards,
Premal Panchal


Hi,
I tried following one:

class RefCountImpl
{
private:
//data members
protected:
void operator delete(void*);
public:
//methods
};
if i have above class implementation.Then in VC++6.0 it works. You can
allocate memory using new but you cannot delete that pointer in your
clilent code. You have to use some method provided by above class to
release the pointer.

Same thing doesnt work in VC++.NET. It clearly throws error that
making delete private cause memory leakage. May be VC++.NET compiler
become more stirct about this. :(.....

First off, that is not the delete operator (despite it''s unfortunate
name) it is the memory deallocation function. Compilers are free to
issue whatever diagnostics they want over the required ones.

Why did you do this?


这篇关于删除操作符私有时获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆