SFML community forums

Help => Graphics => Topic started by: Jeckie on July 19, 2013, 02:17:13 pm

Title: Drawing in class
Post by: Jeckie on July 19, 2013, 02:17:13 pm
I want to put all my drawings in separated file.
Can I do that?
How to do that?
I want all my logic and events in main.cpp.
But drawing in one class named eg Drawing, but I want that class to be in separated file.
Title: Re: Drawing in class
Post by: eXpl0it3r on July 19, 2013, 03:42:25 pm
Maybe by learning C++ in the first place?
SFML requires that you have a good understanding of C++. ;)

Here's a good list with good C++ books (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). :)
Title: Re: Drawing in class
Post by: Jeckie on July 19, 2013, 07:32:03 pm
I have a good understanding of c++.
Just I have always been using class in main.cpp not in separated file.And my question is how to draw everything in there.
Title: Re: Drawing in class
Post by: Gobbles on July 19, 2013, 07:57:05 pm
Without seeing what your doing with your classes it's hard to say how you should handle Drawing code in another file. Normally you would have objects in different files (For example, my Entity class is Entity.h and Entity.cpp and my Entity class handles Updating and Drawing all of the entities).

Maybe provide an example of how you are currently handling your classes? It might give us a better idea to help with.
Title: Re: Drawing in class
Post by: eXpl0it3r on July 19, 2013, 08:31:46 pm
I have a good understanding of c++.
Just I have always been using class in main.cpp not in separated file.And my question is how to draw everything in there.
You had never the need to use multiple files with C++ and don't understand how to separate declarations and definitions, than I know, that your knowledge is lacking on some important features of C++. It's not bad or anything, but it's also not helpful not wanting to read it up in a C++ book that actually explains it. ;)

It's rather simple: Declarations belong into the header file (in C++ preferably with the ending .hpp), while the definitions belong into the source file (.cpp). Every file that wants to use the class/functions needs to include the header file, even the source file that holds the definitions. To prevent multiple inclusions and thus multiple declarations of a class/function one should always add include guards to the header file. The way to do this, that is supported by the C++ standard, is to use #ifndef #define #endif pre-processor commands.
Any good C++ book would cover that. ;)
Title: Re: Drawing in class
Post by: Jeckie on July 20, 2013, 09:51:56 pm
Ok, I'll learn some more c++, but I can't buy any of those books...
Title: Re: Drawing in class
Post by: Nexus on July 21, 2013, 12:36:06 pm
Maybe you can borrow them from a library?

Otherwise, Thinking in C++ is available as a free e-book, you could have a look at that ;)