Jump to content
  • Advertisement

  • User Feedback


    Why not optimize and use virtual function pointers.  The events can be handled through a simple array of functions labeled with maybe enum or something.  I never liked event loops.

    Share this comment


    Link to comment
    Share on other sites

    @codenine75a - The article isn't about event loops. It's about how to avoid circular dependencies with templates in C++.

    Share this comment


    Link to comment
    Share on other sites

    @codenine75a: As Dave Hunt said, this article was about handling circular dependencies with templates in C++, and thus the code samples are at a bare minimum.

     

    I chose to use real world names for the class names, because I personally can't follow advanced code written like "class Foo" and "class Bar".

     

    However, I'm planning some articles about messages and how to use implement and use them in a game. I will not make any promises, but I hope to get them done this year :).

    Share this comment


    Link to comment
    Share on other sites

    @Freya Yeah, it is especially awful when I see code written using "Class A", Class B", "int a"....etc

    BTW I did enjoy the article.

    Share this comment


    Link to comment
    Share on other sites

    Just a note about one comment in the article which is misleading.  "It's not possible to split the declaration and definition into separate files", it is possible, you just have an include after the declarations or include the files in order from another header.  This is fairly common practice with things such as Boost where you put the definition portion of the code in a 'details' directory.  It is not a h versus c file styled break but it does allow you to break the code into logical separate units for well organized declaration and definition portions.

    Share this comment


    Link to comment
    Share on other sites

    Visual Studio is trying to be smart. It can see forwards and there is an implementation (definition) of the Entity class further down below. GCC (g++) is not trying to be smart, and thus the code above fail to compile with g++.

    It's actually kind of the other way around. Visual Studio is still to this day missing two-phase lookup. It works not because it's smart but because it's incorrectly delaying all semantic analysis of the template until instantiation, which while solving issues like this causes other bugs.

    You could actually just modify your templates slightly to make GCC and other standards-conforming compilers happy by making the type of Entity a template parameter to the message handler functions (and hence a dependent type).  Then there will be no semantic checks on the entity parameter until instantiation and everything will work.

    Share this comment


    Link to comment
    Share on other sites

    Just a note about one comment in the article which is misleading.  "It's not possible to split the declaration and definition into separate files", 

     

    It's also possible for template specializations, which granted are only used or useful in certain cases.

    Share this comment


    Link to comment
    Share on other sites


    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!