Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: C++ and Game Development Articles  (Read 9465 times)

0 Members and 2 Guests are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: C++ and Game Development Articles
« Reply #15 on: January 24, 2014, 09:23:29 am »
RAII was a good practice in the past, but if you use std::function you should now that canonical forms of the classes are better. (All classes in modern language have at least a copy constructor or function, a destructor and an affector, and, some language use only pointers for objets, and the pointer have the value null if the objet is not initialized)

Consider the following source code :

class MyClass {
        private :
              sf::RenderTexture text;
              void (MyClass::*func)();
        MyClass () {
 
        }
        void function () {
               text.create(500, 500);
        }
        void anotherFunction () {
                func = &MyClass::function;
        }
}
 

This code wouldn't compile because, the sf::RenderTexture class has no copy constructor or move semantic :

Code: [Select]
error: use of deleted function 'sf::RenderTexture::RenderTexture(const sf::RenderTexture&)'
'sf::RenderTexture::RenderTexture(const sf::RenderTexture&)' is implicitly deleted because the default definition would be ill-formed:|

Imagine that we don't have a rendertexture this time but a resource, the code with a smart_pointer'll not compile, because, smart_pointers are not pointers.

This is exactly why the new c++11 stadart has introduced the move and perfect forwarding techniques. (With the special && operator who's a refenrence to a tempory reference or pointer)

It's an alternative to the RAII mecanism who doesn't work in any cases.

References caused also a lot of problems to store them into a container.
This is why all classes should have at least a move constructor (or copy constructor), a destructor and an affector (even if they're empty), if I want to be very strict, now, if your class doesn't use pointers, you can eventually don't define everything but you have to be sure of what you done, and spetialy if your source code has been to change later. (For some reason you want to use a pointer instead of a ref)

RAII could be usefull in only one case. (but not everywhere as you mention in your article and it's in a very complex case)

When you have a function who uses many and many try and catch blocks or return cases.

You should use a smart_pointer because the finally block doesn't exist in c++, so, the RAII was an alternative.

But, know, rvalues to rvalues operator (the operator&&) allows us to do source code who works in any case, it's easier for code maintenance and it's also faster.  ;)

Your article is good but a bit demoded.



« Last Edit: January 24, 2014, 09:27:43 am by Lolilolight »

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: C++ and Game Development Articles
« Reply #16 on: January 24, 2014, 09:41:09 am »
I'm appalled by your stubbornness Lolo. I don't know if I should laugh or become mad. Anyway I'm sick of it.

Try to remember this when you visit french or english forums :

1. Others topic are not your personal blog
2. Stop bashing at people your methods that, in YOUR opinion, are better (if they are, good for you and too bad for us)
3. Stop mixing pencils and misleading beginners that could come here and there


IF you are the programmer you tell us you are, write a book, good articles, whatever you want but please, please don't do it in here and even less in other's threads.

For the others: sorry for the off-topic, promise I wont do it again
« Last Edit: January 24, 2014, 09:44:36 am by Lo-X »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: C++ and Game Development Articles
« Reply #17 on: January 24, 2014, 10:23:39 am »
Quote
1. Others topic are not your personal blog
2. Stop bashing at people your methods that, in YOUR opinion, are better (if they are, good for you and too bad for us)
3. Stop mixing pencils and misleading beginners that could come here and there


IF you are the programmer you tell us you are, write a book, good articles, whatever you want but please, please don't do it in here and even less in other's threads.

Ok, ok. Anyway I've made a devblog.
So I was no intention to post here any more, so, let's follow his opinion here. (And the mine on another thread)