Hot answers tagged

8

In addition to what Reinderien posted: Look at std::forward_list Your linked list is a single-linked list, the closes equivalent in the standard library is std::forward_list. You will notice from the documentation of std::forward_list that it doesn't implement a push_back(), and its erase() function only takes iterators, not indices. All this is to keep this ...


7

Spelling LincedList -> LinkedList; currectNode -> currentNode; lenght -> length. Factor out iteration Make a private utility method to do this: for(unsigned int i = 0; i < index;i++) currectNode = currectNode->next; return currectNode; given the number of times you do it. Const methods unsigned int size() should be ...


3

It's always going to be ugly Getters and setters are never going to be as pretty in C++ as in some other languages that natively support them. Maybe something nice will be possible in a future C++ standard, but certainly not if you are stuck with C++11. If you are going to use this to proxy member variables of a class, then the best syntax I can come up with ...


3

You should make sure to follow the rule of three/five/zero. In your case we have a user defined destructor, which clears the list by deleting all nodes. Problems arise now when you make a copy of a list: LincedList<int> one(1,2); LincedList<int> two(one); // a copy? When that scope ends, both lists try to delete the same nodes; resulting in &...


2

It lacks a very important functionality - the proxy should be initializable via lambdas / closures. With current API it is impossible to do properly. For instance, consider following code: double x=1, double coef=2.; auto pr = make_proxy(&x, [coef](double*x){return *x*coef;}, [coef](double*x, fouble nx){*x = nx/coef;}); ...


2

No comment on the design, just style improvements. auto pos = std::lower_bound(m_listeners.begin(), m_listeners.end(), m_searchValue, [](const MessageListener& one, const MessageListener& two) { if (one.m_type < two.m_type) return true; else return false; } ); I find this snippet very hard ...


2

Answers to your questions Is the Game object design easy to understand? It's not too hard. But I would have expected a struct Player (even if there is only one instance of it, so no need to put it in a container), and I also expected class Game to manage the monster thread. Does the scheduling mechanism make sense? Yes, but it is a bit too complicated. ...


1

I'm not that great with threads, parallel programming so I won't comment about them... However, as for design decisions; I've taken your code and wrote my own version. I wouldn't say that the code that I'm about to present to you as an example is 100% bug proof. It does currently run and compile producing some interesting results! This has more to do with ...


Only top voted, non community-wiki answers of a minimum length are eligible