PDA

View Full Version : C++ Class's Init / Shutdown



Mr_Smith
03-05-2002, 10:02 AM
Sry this is a bit off topic but yr all gr8 programmers compared to me http://www.opengl.org/discussion_boards/ubb/smile.gif

im using class's and currently have an Init and Shutdown routine so i can init and shutdown some internal things such as textures ect, i looked into constructors and destructors but they cant return values, so i decided not to use them, is thre any reason why i should?

also how do i delete a class, would this work?

HELLO Hi;
Delete Hi;

or

HELLO Hi;
free(Hi);

Thanks, sry its off topic

zeckensack
03-05-2002, 10:16 AM
Read a book (http://www.oreilly.com/catalog/cplus/) or two (http://www.samspublishing.com/catalog/product.asp?product_id={D4BAC475-2EC3-405C-B643-78782992BAAC}) . There is far too much stuff you can do in C++ to discuss it all here.

Bob
03-05-2002, 10:35 AM
As zeckensack said, you should read a book or two on the topic.

Just to answer the questions you had.

If you want your contructor to return error codes, use exception handling.

No, you can't delete classes like that. delete/free is used to release dynamically allocated memory. That is, memory that is allocated at runtime. If you declare a variable/object like "HELLO Hi;", you statically allocate memory, that is, allocated at compile time. These objects live on the stack (dynamically allocated objects lives on the heap), and is automatically deleted once they go out of scope.

If this sounds like greek to you, then again, follow zeckensack advice.

Mr_Smith
03-05-2002, 10:59 AM
+ i didnt think u could, bad advice from a web site http://www.opengl.org/discussion_boards/ubb/frown.gif

Im broke do u know any good online books?

zeckensack
03-05-2002, 11:14 AM
Can't really say how good these are but I've seen them used at some universities and they're free http://www.opengl.org/discussion_boards/ubb/smile.gif
http://www.ibiblio.org/pub/docs/books/eckel/

Mr_Smith
03-06-2002, 03:28 AM
Thx

seu
03-06-2002, 04:20 AM
Originally posted by Mr_Smith:
Sry this is a bit off topic but yr all gr8 programmers compared to me http://www.opengl.org/discussion_boards/ubb/smile.gif

im using class's and currently have an Init and Shutdown routine so i can init and shutdown some internal things such as textures ect, i looked into constructors and destructors but they cant return values, so i decided not to use them, is thre any reason why i should?

also how do i delete a class, would this work?

HELLO Hi;
Delete Hi;

or

HELLO Hi;
free(Hi);

Thanks, sry its off topic

A good online reference would be the C++ FAQ Lite:
http://www.parashift.com/c++-faq-lite/index.html