Search Results

Search found 30 results on 2 pages for 'shachris23'.

Page 2/2 | < Previous Page | 1 2 

  • How to pass a function to a function?

    - by ShaChris23
    Suppose I have a class with 2 static functions: class CommandHandler { public: static void command_one(Item); static void command_two(Item); }; I have a problem DRY problem where I have 2 functions that have the exact same code for every single line, except for the function that it calls: void CommandOne_User() { // some code A CommandHandler::command_one(item); // some code B } void CommandTwo_User() { // some code A CommandHandler::command_two(item); // some code B } I would like to remove duplication, and, ideally, do something like this: void CommandOne_User() { Function func = CommandHandler::command_one(); Refactored_CommandUser(func); } void CommandTwo_User() { Function func = CommandHandler::command_one(); Refactored_CommandUser(func); } void Refactored_CommandUser(Function func) { // some code A func(item); } I have access to Qt, but not Boost. Could someone help suggest a way on how I can refactor something like this?

    Read the article

  • C++ std::equal -- rationale behind not testing for the 2 ranges having equal size?

    - by ShaChris23
    I just wrote some code to test the behavior of std::equal, and came away surprised: int main() { try { std::list<int> lst1; std::list<int> lst2; if(!std::equal(lst1.begin(), lst1.end(), lst2.begin())) throw std::logic_error("Error: 2 empty lists should always be equal"); lst2.push_back(5); if(std::equal(lst1.begin(), lst1.end(), lst2.begin())) throw std::logic_error("Error: comparing 2 lists where one is not empty should not be equal"); } catch(std::exception& e) { std::cerr << e.what(); } } The output (a surprise to me): Error: comparing 2 lists where one is not empty should not be equal Observation: why is it the std::equal does not first check if the 2 containers have the same size() ? Was there a legitimate reason?

    Read the article

  • Qt Should I derive from QDataStream?

    - by ShaChris23
    I'm currently using QDataStream to serialize my classes. I have quite a few number of my own classes that I serialize often. Should I derive QDataStream to create my own DataStream class? Or is there a better pattern than this? Note that these custom classes are used by many of our projects, so maybe doing so will make coding easier. Another way to phrase this question is: when a framework provides you with a serialization class, how do you handle serializing your own custom-type classes such that you don't have to remember how to serialize them everytime.

    Read the article

< Previous Page | 1 2