几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-05-04, 06:01 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】compiler errors with the new operator

compiler errors with the new operator
compiler errors with the new operator
hi,
i'm using visual c++ 2003.
i've got the following compiler error:
error c2660: 'odrxobjecterator new' : function does not take 3 arguments.
i tried to use the using operator new, but have this:
error c2143: syntax error : missing ';' before '('
error c2238: unexpected token(s) preceding ';'
what should be the exact stuff to write?
for example this is the code producing the first error:
code:
class caoimodeldrawable : public odgsbasemodeldrawable
{
public:
caoimodeldrawable(odgsbasemodel* pmodel, odgidrawable* punderlayingdrawable)
: odgsbasemodeldrawable(pmodel, punderlayingdrawable) {}
private:
virtual bool valid() const
{ return true; }
virtual void invalidate(odgsmodel::invalidationhint = odgsmodel::kinvalidateall)
{}
};
//and the line producing the code:
odgsbasemodeldrawable* mymodel::createnewwrapperobject(odgidrawable* punderlayingdrawable)
{
return new caoimodeldrawable(this, punderlayingdrawable);
}
thanks in advance for any help.
regards
chudomir
this error seems to be caused by the macro:
#ifdef _debug
#define new debug_new
#endif
which makes the new operator being a diagnostic one.
when i turn off this macro, then the code is compiled.
but i think thus i lose the memory leak detection.
is there a way to combine them both?
thanks in advance for any help
regards
chudomir
workaround
with regards to this problem (which i had as well), i used the following workaround (prompted by a suggestion somewhere else in the forums):
code:
#ifdef _debug
#undef this_file
static char this_file[]=__file__;
#define new ::debug_new
#endif
instead of:
code:
#ifdef _debug
#undef this_file
static char this_file[]=__file__;
#define new debug_new
#endif
this forces all instances of "new" in the target module to explicitly use the global new operator which (if you are getting this error) has been overloaded to include the line number and filename of the allocation context.
note: this basically will override any implicit "new" behavior, which may be undesirable in some custom allocation circumstances. for my part, i was just turning this on to track some memory leaks.
quote:
originally posted by chudo
this error seems to be caused by the macro:
#ifdef _debug
#define new debug_new
#endif
ok...so it compiles okay...but you will likely need to add a
code:
#define delete ::delete
as well... otherwise your deallocate will be "exceptional" in a bad way.
after having gone down this path a bit further, there are further complications, not the least of which are that mfc classes (cobject-derived) use their own new/delete operators, so if you override a creation/deletion that you control, and a creation/deletion occurs that you do not control, then you are hosed. the short story is, this may not get you far...
a better solution...
with a bit more delving, i have come across a better solution still. in odheap.h, there are macros for adding class-specific implementations of the heap operators (odrx_heap_operators() macro). although it is too late for any well-defined classes from the od libraries, derived classes can use this macro to define how they will allocate/deallocate. i have extended this macro to include mfc-style line-and-number memory operators in debug mode. it goes something like this:
code:
#ifdef _debug
#define my_heap_operators() \
odrx_heap_operators() \
void* operator new(size_t s, lpcstr f, int l) { return :perator new(s, f, l); }\
void operator delete(void* p, lpcstr f, int l) { :perator delete(p, f, l); }\
void* operator new[](size_t s, lpcstr f, int l) { return :perator new(s, f, l); }\
void operator delete[](void* p, lpcstr f, int l) { :perator delete(p, f, l); }
#else
#define my_heap_operators() odrx_heap_operators()
#endif
just use my_heap_operators() in the class definition (in lieu of odrx_heap_operators) and you should be good for mfc-style "new" overloads (through debug_new macro)
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】compile errors when deriving a class from oddbdxffiler yang686526 DirectDWG 0 2009-05-04 06:00 PM
【转帖】[翻译] metaprogramming with autocad (二) - 精华帖集合 yang686526 ObjectARX(VB.NET/C#) 0 2009-04-29 05:02 PM
【转帖】关于C++的构造函数, 复制构造函数 和 operator = huangyhg 运行效率 0 2008-11-27 06:31 PM
Where do errors and uncertainties come from? yogy 坐标测量机 0 2007-07-22 05:16 PM


所有的时间均为北京时间。 现在的时间是 05:52 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多