• Content count

  • Joined

  • Last visited

Community Reputation

758 Good

About stylin

  • Rank
  1. Overloading Functions

    Essentially what BringBackFuturama said. I would also point out that in any non-trivial program, ctors are overloaded (necessarily) all the time. Function overloading is also convenient for compile-time dispatch, where, using the same name, multiple functions can be called based on a type (or trait). In this case, templates do not provide a solution, and in fact are often overloaded themselves (look inside your standard library headers sometime for some examples).
  2. One advantage of the Command Pattern is that it let's you rollback deterministically, meaning it gives you the what and when information. It might be expedient to have such information to efficiently prepare for a high-level user Undo command (I assume the pattern would pervade not only end-user actions, but engine actions as well). It also largely depends on how your system is currently set-up. Integrating Command can be alot of work if you're only going to use it in a small subset of your program. Typically, though, Command is a good choice, especially for non-intensive applications.
  3. Vector of Objects (C++)

    My apologies, I thought you might be suggesting that you should provide a non-member friend function to retrieve the new data based on a private implementation of the object. If not, I wondered about the relationship between the two to suggest either inheritance or composition.
  4. Vector of Objects (C++)

    mutable refers to the ability of const member data (in the context of a const instance) to be modified by const member functions. You may be referring to the friend keyword. What relationship does the new data and the object have?
  5. How should I make my 'dungeon'?

    If your maps' sizes are fixed then a simple array (std::vector) is a common approach. For objects, either dynamically or hard-coded into the map, the interactivity depends on the object itself. For example, all objects may have a void Touch() interface that allows derived objects to override different behaviour. Depending on how you implement intra-Room navigation, a dynamic structure might be a good option to persue - whether it be some sort of 2D array, or a linked-list (each Room points to a not-necessarily-adjacent Room. This allows for the easy addition of more than the 4 cardinal exits: a staircase or a dimensional warp, for example). The size of your Room class shouldn't be affected by the size of the map, only how you implement it. A Room and a Map may fit the "derived is-a base" relationship, so public inheritance is one possible solution. Another would be to "implement a Room in terms of a Map", meaning the Room would either compose a Map object and forward requests (like a certain tile @(x,y), what object are currently in the map, etc.) to it, or privately inherit from a Map class (they mean the same thing). Personally, I would recommend to start out with a simple Room class containing an array of map tiles, a list of objects currently in the room, and a few directional functions to indicate the Room in that direction. The design could be made more robust, but that's a relatively quick and easy implementation. Happy hacking! [smile] edit: details assuming C++ [Edited by - stylin on May 4, 2006 12:54:55 AM]
  6. Enums and classes

    What is the exact compiler error message? I'm going to out on a limb and assume you're talking about some form of IDE code-completion tool (like Intellisense). I get no errors with superpig's code for VC++2005E - and Intellisense reads the class members perfectly. What compiler/IDE are you using?
  7. C++ inner class

    Add default base class construction to that [initialization] list. The initialization of const and reference member data also makes writing an empty ctor sometimes necessary (since these members must be initialized in the list). Apart from initialization issues, the idioms mentioned that come from non-public declaration/definition of default ctors and assignment ops are really the only purpose they serve. I'd much rather prefer a '// relying on default ctor behaviour' comment or none at all than having to read through the code.
  8. C++ inner class

    One advantage is that you have less code to write, which means less code to make typos on. Another reason is that other programmers may assume 'abnormal' behaviour in your constructors because you defined one, albeit a default one which does nothing. Do nothing code should typically be gotten rid of. For default constructors and assignment ops, it only adds visual noise. edit: 'does nothing' as in 'serves no purpose'. [Edited by - stylin on May 3, 2006 5:20:03 PM]
  9. Another 'book' question...

    This site has loads of books and reviews. You'll not only be able to see if they include exercises, but in some cases a table of contents is provided as well. [smile]
  10. Happy National Walkout Day!!

    From the linked article: Quote:"We are the backbone of what America is, legal or illegal, it doesn't matter," Melanie Lugo, who with her husband and their third-grade daughter was among thousands attending a rally in Denver, Colorado, told The Associated Press. Quote:The call to not work, not go to school, not go shopping was heard in many other cities too. Quote:In San Diego, California, Benita Olmedo told the AP she had pulled her 11-year-old daughter and 7-year-old son from school to join a march there. Quote:"I want my children to know their mother is not a criminal," said the nanny who told the AP she came here illegally in 1986 from Mexico. "I want them to be as strong I am. This shows our strength." Or, a lack of good-parenting. Yep, the kids are being home-schooled today - and the lesson is dis-illusionment! Seriously, if I was Lugo, I wouldn't be bragging of the backbone I represent. "Break the law? We deserve the right to!" Huh? Nice example for your kids.
  11. Gradius Type Enemy Question

    Many enemies in Gradius (eg., the ones in your pic) seem to follow a simple sine wave for their initial attack. Other enemies (like the ones that fly out of those dome-like thingies) fly straight up until their altitute is equal to that of the player, then simply fly in her direction. Most of the enemies have pre-scripted flight paths, but they will typically diverge from that after the initial wave and just hone in on the player. Your enemies need to keep track of state, which includes of course their velocity and the flight path their currently flying. Most of the pre-scripted flight paths in Gradius stop either when they reach the player or when they reach the edge (left) of the screen, so their current flight path state predominantly depends on their position as opposed to time - although I would assume a few have time-based choreography. What language will you be implementing this in?
  12. Quote:Original post by TheTroll If you write your own linked list then you can call them roughly the same way that you where calling them before. Among other things, you'll also have to worry about memory management. It's not worth it to roll your own when there are evaluated, tested and debugged implementations out there for free, IMO.
  13. You'll use an initialization list: Square::Square(Square const & dx) : Shape(dx) { ... }
  14. Purpose of std?

    Quote:Original post by ItsNotATumaaa It says you could use the new standard <iostream> and using namespace std; or you could use the old way, and that the changes are subtle, esoteric, and beyond the scope of the ductory primer. In many ways the differences are not as trivial as the books suggests. You should prefer the new-style (dot-less) headers for all new projects you write. Quote:Also, what is the purpose of std? std is the namespace dedicated to the C++ Standard Library. Much of it comprises the STL, and it even has wrappers that incorporate headers from the C Run-time Library (math.h, time.h, stdio.h, etc.) into the (std) namespace. Because of this, you should prefer to use these wrapper headers (cmath, ctime, cstdio, etc.) for portability reasons. I haven't read your particular book, but my experience with Sam's is that they generally are not as comprehensive as I'd like - even for a beginner's book. If the book doesn't cover - or only has a mention of - std::string, then I'd probably want to grab a newer/more C++ orientated guide.
  15. So your base container contains base objects, while a derived container holds derived objects? Using polymorphism, the derived container need not hold anything; the base container already holds pointers to base objects. The derived container's only purpose would be to provide additional functionality to the base container, not base objects. In other words, you don't need a derived container to extend derived object functionality - the derived object already does that. You initialize a game object (weapon, et al.), then place it into your base container. What additional functionality do these derived containers provide? (I question their necessity)