|
classes: a pain in the ass. |
Albin Engström
Member #8,110
December 2006
|
you know this thing they call classes? i hate it.. if i could, i would stick to structures and having all the code in one file, but after a while you get kinda tired of never finding what you're looking for.. so this morning i started to learn about classes (for real..), seams like it can't be mastered in one hour.. i think classes is very confusing.. a long time ago i thought classes was used to link files of code making it easier to manage your project.. i don't have to use classes right? isn't there a tutorial on this shit?? The question is: How do i alter use_triple_buffering in configuration.h from initialization.cpp function dynamic_initialization?(example) i've tried many things and it to complex to google..
/*initialization.h :S*/ #ifndef INITIALIZATION_H #define INITIALIZATION_H class initialization { public: initialization(); ~initialization(); void static_initialization(); void dynamic_initialization(); void de_initialization(); }; #endif
/*configuration.cpp :|*/ #include "configuration.h" //con configuration::configuration(){} //des configuration::~configuration(){}
|
Marco Radaelli
Member #3,028
December 2002
|
Quote: The question is: How do i alter use_triple_buffering in configuration.h from initialization.cpp function dynamic_initialization? You need a reference in initialization to an object of type configuration. And you need to add a setter to the configuration class (like void set_use_tb() { use_triple_buffer = true; } ), but I think you're not using classes the way they're meant to be used. For instance, a class should contain all the properties that make up a state, plus the operations to manipulate that state. So, in your case I would do a game class, that will initialize things in its constructor (there's no need to add that static_initialization(), if you put that code in the constructor it will be called when the variable in created). [edit] The main difference between structs and classes is that the latters let you specify properties and operations to be executed on them in a single, close, object. [edit2] Another point: it's not always the best to separate things in the code just because they are in real life (above all if you then need a reference to keep the objects together, like initialization and configuration).
|
X-G
Member #856
December 2000
|
I would just like to add that this is not the right way to use OO. This is just procedural programming pretending to be something else, so no wonder it's coming off as strange... -- |
Albin Engström
Member #8,110
December 2006
|
Marco Radaelli said: but I think you're not using classes the way they're meant to be used neither do i.. thank you, X-G said: I would just like to add that this is not the right way to use OO. This is just procedural programming pretending to be something else, so no wonder it's coming off as strange... |
X-G
Member #856
December 2000
|
-- |
Paul whoknows
Member #5,081
September 2004
|
You don't need a class for your allegro game initialization, that can be simple done with some ifs. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Matt Weir
Member #7,476
July 2006
|
If you really want to learn this stuff a book is probably the best way to go. Probably not the 'dive right in' answer you seem to be looking for but Object Orientated programming is a completely different mindset to structured programming and you need to learn some new concepts. I've read a lot in the past and most were good enough to get you through all the basics. While a I can't remember what the best book I've read is, any of the following were good enough should be at your library, school etc. Teach yourself C++ in 24 hours (don't be suckered by the title...) Once you start learning a bit you'll wonder why you didn't start earlier! It's really useful stuff. Matt Weir. |
23yrold3yrold
Member #1,134
March 2001
|
Quote: you know this thing they call classes? i hate it.. if i could, i would stick to structures Go for it. Structs are just classes whose members default to public instead of private. .... yes, I know what you're saying, but I had to throw that out there. -- |
Tobias Dammers
Member #2,604
August 2002
|
Quote: Teach yourself C++ in 24 hours (don't be suckered by the title...)
Bad choice. Quote: Dummies guide to C++ (don't let the 'Dummies guide' bit blind your judgement in thinking the book is crap) Haven't really tried that. My choice would have to be Bruce Eckel's Thinking in C++. Available on-line for free, but in my experience, a printed book is always nice to have next to your computer. OT: #ifndef ALLEGRO_SETUP_H #define ALLEGRO_SETUP_H // everything else goes here. #endif 4. For each function that is needed in another module, put the function declaration into the header of its own module, and include the header into the .cpp file of the module that needs it. For example, the main loop will probably use a function called flip() from the screen buffer module. So you have:
5. Put all type definitions (including struct types) into the header file for their module. // ---- module.h ---- #ifndef MODULE_H #define MODULE_H extern int this_is_globally_available; #endif // ---- module.cpp ---- int this_is_globally_available = 23;
7. NEVER include a .c or .cpp file. When you come to realize that certain groups of variables and functions "belong together", then you have a candidate for a class. But I suggest you read up on OO design before doing actual coding; and it's probably a very bad idea to apply OO design to an already existing project. Design in OO paradigm from the start, or keep the project procedural. --- |
James Stanley
Member #7,275
May 2006
|
Quote: if i could, i would stick to structures and having all the code in one file, but after a while you get kinda tired of never finding what you're looking for Um... You're allowed to use more than one file when you use structs... |
ImLeftFooted
Member #3,935
October 2003
|
Quote: think classes is very confusing.. a long time ago i thought classes was used to link files of code making it easier to manage your project.. i don't have to use classes right? Classes are just structs with a few extra features. |
Hard Rock
Member #1,547
September 2001
|
Personally for books I'd recommend "C++ the complete reference" which is significantly better then the Java book by the same author. It's really easy to read and does cover MOST of the important concepts you'll need to learn. However for indepth knowledge you'll need "The C++ Programming Language", which is THE C++ book. _________________________________________________ |
Albin Engström
Member #8,110
December 2006
|
thanks!! i'm more of a writing person than a reading one.. in all aspects of life. |
|