Board index » cppbuilder » 2 questions: C++ and DirectX Clipping

2 questions: C++ and DirectX Clipping

C++ Question:

How would you make a class return NULL if it did not initialize
properly?

eg:     MyClass *Class = new MyClass;
        if (Class == NULL) ...

Or does this only work with copy constructors?

Direct X Clipper Question:

I've set up a Direct Draw Clipper to run in a Window, but when I move
the window, DD still draws from the upper left of the screen, not the
window. So, if I move the window down and right by say 20 pixels, DD
leaves 20 pixels to the right and bottom of the window blank.  How do I
get around this?

TIA,
-Jeff

 

Re:2 questions: C++ and DirectX Clipping


Quote
"Chris Uzdavinis (TeamB)" wrote:
> You should post DirectX questions in the graphics newsgroup and not in
> the language group.

Oops, you posted it in the IDE group.  So both of your questions were
off topic. :)

Please make an effort to be on topic... (everyone!)
--
Chris (TeamB)

Re:2 questions: C++ and DirectX Clipping


Quote
JC Moxon wrote:

> C++ Question:

> How would you make a class return NULL if it did not initialize
> properly?

> eg:     MyClass *Class = new MyClass;
>         if (Class == NULL) ...

> Or does this only work with copy constructors?

You cannot do that in either case, at least not directly.  When you
say "does not initialize properly" do you mean that a problem occurred
during the constructor, or that new() failed to allocate enough
memory?

If an exception is thrown in the constructor, you can be certain that
no memory was allocated.  However, your pointer will remain
uninitialized.  (But this is obvious because you're either in a catch
block or the program terminates.)

If new fails, it also throws an exception.  However, you can disable
the new() exception by calling this:

#include <new.h>
...
set_new_handler(0);

and from then on new() returns NULL when it fails.  

You should post DirectX questions in the graphics newsgroup and not in
the language group.

Quote
> Direct X Clipper Question:

[snip]
--
Chris (TeamB)

Other Threads