|
-
Apr 29th, 2002, 08:05 PM
#1
Thread Starter
Member
Casting a CRect object/pointer to a CObject pointer
I am trying to use the following line of code to cast a CRect to a CCbject:
CObject* pHint=DYNAMIC_DOWNCAST(CObject, mRects[x][y]);
but I get an error stating "none of the two overloads can convert parameter 2 from type 'Class CRect*'"
I need this to use in CView OnUpdate so that I only redraw part of the screen.
-
Apr 30th, 2002, 05:30 AM
#2
CRect is not derived from CObject.
But you can use brute pointer casting:
UpdateAllViews(NULL, 0L, reinterpret_cast<CObject*>(&rcUpdate));
Just remember to cast it back in OnUpdate.
A tip: if you're ever going to use a selfmade struct UPDATE_PARAMS (or something like that), you may want to add a CObject* operator to the struct:
Code:
struct UpdateParams
{
int type;
CRect rcUpdate;
long id;
operator CObject*() { return reinterpret_cast<CObject*>this; };
};
// somewhere:
UpdateParams up;
// set members
UpdateAllViews(this, 0L, up);
This makes it easier to write and read, and since you don't use UpdateParams anywhere else (hopefully), it isn't a type safety hazard IMO.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|