PDA

View Full Version : why does this line of code work?



chris.kulhanek
2006-06-29, 06:40 PM
can someone help me? why does this line of code work?

AcDbObjectId lineId = AcDbObjectId::kNull;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);

shouldn't it be this....


AcDbObjectId *lineId = new AcDbObjectid();
pBlockTableRecord->appendAcDbEntity(lineId, pLine);

what is AcDbObjectId? when used, shouldn't it need to be instantiated with a pointer?

Paul Bryan Porter
2012-01-09, 08:53 PM
>what is AcDbObjectId?

It is an ObjectARX class. It represents a somewhat generic identification of an AutoCAD Object.

>shouldn't it need to be instantiated with a pointer?

A class can be instantiated without having to call new. i.e.
AcDbObjectId currentViewPortId = acedGetCurViewportObjectId();

>why does this line of code work?

This is the real question! I believe what is going on is the AutoCAD ObjectARX developers have overwritten the = sign to make it a copy constructor. They are trying to initialize an object id by saying this value is NULL. The AcDbObjectId class has two methods, isNull and SetNull. You can use these two methods later to see if you have a valid AcDbObjectId or invalidating an AcDbObjectId. The K::Null is another way of setting it the lineId to NULL.

You might want to try,

AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);

and see if it works. The = AcDbObjectId::kNull might not be needed at all.

Paul


can someone help me? why does this line of code work?

AcDbObjectId lineId = AcDbObjectId::kNull;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);

shouldn't it be this....


AcDbObjectId *lineId = new AcDbObjectid();
pBlockTableRecord->appendAcDbEntity(lineId, pLine);

what is AcDbObjectId? when used, shouldn't it need to be instantiated with a pointer?