Jump to content
  • Advertisement

Bill Door

  • Content Count

  • Joined

  • Last visited

Community Reputation

360 Neutral

About Bill Door

  • Rank
  1. Bill Door

    Compile time "polymorphism"

    A similar (but more in-depth) technique I have used is called "Runtime Polymorphism" or originally "Concept-based Polymorphism". This polymorphism is different than inheritance. The technique is described in "Better Code: Runtime Polymorphism" (PDF) and in the video "Value Semantics and Concepts-based Polymorphism" from C++ Now! 2012.
  2. Regarding casting -- #gonrogon advice is sound. To add a bit, whenever you use a cast, any of the cast's but especially C-style casts, you are saying that you are smarter than the compiler. That's a risk that I don't like to take unless I am very confident.    If I use a cast, it's because I tried without the cast and the compiler told me what I needed to do to get the cast that I wanted. The compiler is your friend.
  3. Your example works because the deleted object is the type with the virtual destructor.  e.g.        B *p = new AB;     delete p;   However,       A *p = new AB;     delete p;   I would expect that this would not call the destructor for AB or B.   In the first example, the object is of type B, which has a virtual destructor, which causes the virtual table to be used which calls the destructor for AB, which in turn destroys, A and B.   As an object of type A, the compiler has no idea that it should do anything except call the destructor for A. There is no virtual table to access, so only the destructor for A is called.
  4. Your ROOMCLASS is not properly copyable. A vector copies and owns each object as it is inserted into the vector. A new ROOMCLASS instance is created using the copy constructor and the old one is deleted. vector requires copyable classes. I expect that you wrote ROOMCLASS so that it properly destroys the texture when it is deleted. You need a system for copying the texture reference or creating a new texture reference in the new instance of ROOMCLASS. shared_ptr is often referred to for this purpose. I consider shared_ptr a crutch. Each class should learn to manage it's own resources. In this case, perhaps a management class for textures that uses shared_ptr would be useful. I would avoid using shared_ptr as a requirement for using HOUSECLASS.
  5. This is not the canonical method of erasing elements from a vector. Take a look at remove_if in algorithms. The typical problem is that the iterator is invalid after the erase. iterator it = remove_if(enemyVector.begin(), enemyVector.end(), YourPredicate); Then use this new iterator to visit the removed elements to delete them. I would then revisit to erase all in one block. for_each(it, enemyVector.end(), DeleteFunction); enemyVector.erase((it, enemyVector.end()); Three functions calls, two simple (inline) functions.
  6. The question would be why do you think STL has "overhead"? Each container has it's expected expectations and limitations. Understand the expectations and limitations to make your decisions. The c++2011 defines an unordered map (aka hashtable). If you're not using a C++-2011 installation, then you should be able to find something compatible (e.g. boost).
  7. Bill Door

    C++ As First Language

    I find it interesting how people seem to overstate how difficult it is to learn programming from C++. I teach high school students programming using Stroustrup's Programming: Principles and Practice Using C++. This is a text book for an introductory course on computer programming. The students have found the book to be readable, engaging, and useful. There are practical exercise in learning to solve real problems in programming. The language choice is naturally C++. I find C++ to be fine as an introductory programming language.
  8. Bill Door

    Pointer to class type?

    Take a look at Design Patterns. In particular the State and Strategy pattern. This might help you to work out a solution. I often find the flyweight pattern useful for state machines.
  9. Bill Door

    Need C++ Help

    C++ is a fine language to learn. I teach C++ programming to high school students as a first language. You do not need to learn C first. In fact, learning C first can be a handicap. I introduce programming to the students using Programming -- Principles and Practice Using C++. This book teaches programming, while using C++ as the example language. Learning the techniques of problem solving with programming is key to learning to program. C++ is the language of choice for this book. Good luck and Enjoy.
  10. Bill Door

    Question about inheration

    In C++, once virtual always virtual. The declaration of virtual in the base class is sufficient. Overrides in other subclasses will also be virtual.
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!