• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

1020 Excellent

About jflanglois

  • Rank
  1. generic linked list -template?

    I realized that you had your own implementation, but unless you're writing a linked list implementation for academic purposes, you should be leveraging the standard library (and some other well regarded libraries) as much as possible. But to answer your specific question: yes, you would use templates in this case. I should warn you that the implementation for std::list in your stdlib probably won't be readable. I would look instead at the C++ standard documents to find out what the requirements for the stdlib container classes are.
  2. generic linked list -template?

    The best way is to use the standard library. std::list is a doubly linked list in most implementations, as far as I know (its complexity requirement basically mandate it, if I remember correctly, but I haven't developed C++ code in a long time). The benefit of going with the stdlib is that it deals with use cases that you may not have thought about (e.g. (de)allocation), and the code is likely very well tested.
  3. Simple override problem [SOLVED]

    As Kasya has touched on, dynamic dispatch is accessible through pointers in C++: #include <iostream> struct Entity { void animate() { std::cout << "Entity::animate" << std::endl; } virtual void vanimate() { std::cout << "Entity::vanimate" << std::endl; } }; struct Player : Entity { void animate() { std::cout << "Player::animate" << std::endl; } void vanimate() { std::cout << "Player::vanimate" << std::endl; } }; int main() { Entity e; e.animate(); e.vanimate(); Entity p = Player(); p.animate(); p.vanimate(); Entity * pe = new Entity(); pe->animate(); pe->vanimate(); delete pe; Entity * pp = new Player(); pp->animate(); pp->vanimate(); delete pp; } Output: Entity::animate Entity::vanimate Entity::animate Entity::vanimate Entity::animate Entity::vanimate Entity::animate Player::vanimate That being said, you need to be careful to manage your memory when using a collection of pointers. I recommend looking at the Boost Pointer Containers library or a collection of TR1/Boost Smart Pointers. [edit] Also, I would take a look at standard library algorithms, particularly for_each (or transform, depending on what you're doing) to apply a function against a collection. [edit2] Speaking of memory management, forgot the deletes (although the runtime very likely reclaims the memory on exit). [Edited by - jflanglois on May 9, 2010 12:08:49 PM]
  4. Cross domain browser elements

    You have opted in, though, by signing up for the service. Although I agree that you should have more control over how you interact with these services, I think that a technology solution would only serve to mitigate the problem. The debate, I think, really belongs in the legal space.
  5. Cross domain browser elements

    Well, the problem is that it would break legitimate uses for cross domain requests, such as content delivery networks. The better solution is to blacklist the domains you don't want (and you don't need a plug-in to do that), but then the issue is: nothing is free; so would you rather Facebook was a paid service, or would you rather the slight annoyance and award them their advertisement revenue? [Edit] Re: privacy. If you are truly worried about privacy, then I would recommend you stay away from Facebook altogether. Mark Zuckerberg has made it clear that he believes privacy is no longer relevant in social media (though he will try to make his users happy, naturally). [Edit2] Also, cross-site ajax requests are a part of XHR Level 2, and modern browsers are gaining support for it(e.g. Firefox, WebKit). And that ignores techniques like JSONP. [Edited by - jflanglois on May 9, 2010 11:13:39 AM]
  6. When can I call myself a computer scientist?

    Probably once you realise that computer science is neither about computers, nor particularly a science (in the sense that science is the application of the scientific method).
  7. what is the meaning of this statement?

    It means, switch the bit in the b'th position in a to 1. Assuming we're talking about numbers here.
  8. std::vector

    Quote:Original post by shotgunnutter Quote: Also, it's perhaps slightly more idiomatic to use vector::push_back() to add elements to the end of a vector. what would that look like? characters.push_back( tmp_character );
  9. std::vector

    characters.back(). Also, it's perhaps slightly more idiomatic to use vector::push_back() to add elements to the end of a vector. By the way, why do you have a vector of pointers to characters? Why not just a vector of characters?
  10. STL compiler error......

    You cannot copy streams in C++. It's unfortunate, but that's how it is. You're best bet is to either hold a string, or a smart pointer to the stream, depending on what your intent is. jfl.
  11. Quote:Original post by ehmdjii edit: here is the stacktrace: http://rafb.net/p/LWsshn71.html Right. So what is operator< for tobstacle, and what is tcollision::tdetect?
  12. What is the definition of tobstacle's operator<? That error message means that you have not defined a strict weak ordering (or that you are performing an operation that requires a sorted sequence on an unsorted sequence). edit: Could you show us the stack trace for the assertion? jfl.
  13. Corking Memory Heap leaks?

    What is the exact error message? More code would be useful too.
  14. string tokenizing and parsing...

    Quote:Original post by CDProp That seems like a good way to go as well. Does the >> operator stop on all whitespace characters, i.e. tabs and \n's and \r's? Yep, it stops on all whitespace. Another reason to use it is that you don't need to deal with character arrays.
  15. When you get these kinds of errors and you can see that it refers to a library function (unresolved external symbol _DirectDrawCreateEx@16), go to the documentation, and take a look at the library requirements section: Quote:Import Library: Use ddraw.lib So you need to add ddraw.lib to your linker dependencies. In VS2005, this can be found in Projects->Properties->Configuration Properties->Linker->Input->Additional Dependencies. jfl.
  • Advertisement