Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

Cloaca

@Cloaca
About
Posts
23
Topics
6
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Strategy question
    C Cloaca

    Hi Maxwell, Thanks for the idea! :) Best, Eric

    C / C++ / MFC help tutorial question

  • Strategy question
    C Cloaca

    Hi Maxwell, I don't have ready access to Borland Builder. Can you point me to some ideas on the web. Searching Google gave me some ideas, but from what I can tell it looks somewhat like the Visual Studio IDE. Thanks for the reply! Eric:)

    C / C++ / MFC help tutorial question

  • Strategy question
    C Cloaca

    Hi everyone, I am starting a program that will allow serveral files to be viewed at once. My idea is to start with a dialog based app and then open other windows (sort of like views) to show each file. The files will be chosen from the main dialog of the app. The main dialog will also keep a list of the open files (windows) and allow the list of open files to be saved, and it will have a 'New' button so that new files can be created. My question is about how to go about making these 'view' windows. I don't want to use MDI (since I want the user to be able to move the windows around without them all being stuck in a frame) and I can't use modal dialogs since they would block access back to the main app's dialog while they're open. I was thinking about using modeless dialogs or going through the process of AfxRegisterWndClass and 'rolling my own' display windows. What ideas do you have about how I should approach this. If I do my own windows, I'll need to handle mouse and keyboard events within them, and it seems like that stuff is somewhat provided (skeleton laid-out at least) to me if I use dialogs. Thanks much, best regards,:) Eric

    C / C++ / MFC help tutorial question

  • Doubts with sorting stl vector...
    C Cloaca

    Hi antlers, Ahh. I think that puts it together for me. A function is of course not a type. But by using the 'struct method', you kind-of wrap the function in a type. And so it is acceptable to the algorithm at compile time. The syntax of operator() is the way a wrapped function can be exposed to the algorithm for use in, for example, a sort call as a comparison. And this minimal extra work is the small price to pay for a very flexible system of getting whatever might be needed into the templated algorithms. I see. Thanks very much for your help, I appreciate it! :) Best, Eric

    C / C++ / MFC c++ graphics algorithms help question

  • Doubts with sorting stl vector...
    C Cloaca

    Hi jhwurmbach, Thanks for your reply. That makes sense, but it then makes me wonder why I need a class (or struct) at all to hold the comparison function. Why is it that I just can't declare the comparison function (just as a 'simple' member of CFoo) and pass it to the stable_sort() call? I have been reading about operator() and functors, but I am not putting it all together yet, I guess. Does it have someting to do with the fact that functions passed to the algorithms can only have one parameter? I appreciate your help, thanks again! :) Eric

    C / C++ / MFC c++ graphics algorithms help question

  • Doubts with sorting stl vector...
    C Cloaca

    You are right David. That's a good point also. I should male it a policy not to repost for a week or so I guess. Thanks again, Eric :)

    C / C++ / MFC c++ graphics algorithms help question

  • Doubts with sorting stl vector...
    C Cloaca

    Hi Kuphryn, I will grab these two references that you noted. And thanks for the comment on the way I'm doing it now, I appreciate your input! Thanks very much, Eric

    C / C++ / MFC c++ graphics algorithms help question

  • Doubts with sorting stl vector...
    C Cloaca

    Hi David, I know. And I knew that I risked being rude, but I figured that since it was late when I left the post it might not get seen by many, so I took the chance. Anyhow, I take your point and I appreciate your feedback. Best, Eric

    C / C++ / MFC c++ graphics algorithms help question

  • Doubts with sorting stl vector...
    C Cloaca

    Hi everyone, I have a class like this:

    // Header file
    class CFoo
    {
    public:
    CFoo();
    ~CFoo();
    BOOL SortByName();
    // Other functions declared here...

    protected:
    std::vector<CRec*> m_Recs; // CRec is a class with CStrings, etc.

    private:
    struct NameComparer
    {
    bool operator()(const CRec* A,const CRec* B)
    {
    return ((A->m_strName) < (B->m_strName));
    }
    };
    };

    // CPP file
    // Other functions are defined here...
    BOOL CFoo::SortByName()
    {
    std::stable_sort(m_Recs.begin(), m_Recs.end(), NameComparer());

    return TRUE;
    

    }

    Now, basically, I am trying to properly write and use a predicate function (I think that's what they're called; please correct me if I'm wrong) in the context of calling std::stable_sort (and just std::sort for that matter). There are many helpful examples around, but they don't seem to cover dealing with a non-trivial class (or if they do I haven't 'gotten it' yet). In my case, I want to be able to sort the vector of CRec's according to several different CRec member variables (different CStrings, ints, doubles, etc.). My questions are: 1) Did I use proper coding techniques to solve the problem as I have shown here? 2) Is it the case that I need to add additional structs under the private section of CFoo for each comparison CFoo member function I want to write (with the comparisons applied to the std::vector m_Recs and based on the CRec members themselves actually)? 3) Why do I need to wrap the comparison functions in a struct? How does that fact relate to operator(), etc.? Thank you all again for reading and giving any advice, Best, :) Eric

    C / C++ / MFC c++ graphics algorithms help question

  • Using stable_sort with predicate function: Help please.
    C Cloaca

    Any ideas? :((

    C / C++ / MFC help c++ graphics question

  • Using stable_sort with predicate function: Help please.
    C Cloaca

    Hi everyone, I have a class like this:

    // Header file
    class CFoo
    {
    public:
    CFoo();
    ~CFoo();
    BOOL SortByName();
    // Other functions declared here...

    protected:
    std::vector<CRec*> m_Recs; // CRec is a class with CStrings, etc.

    private:
    struct NameComparer
    {
    bool operator()(const CRec* A,const CRec* B)
    {
    return ((A->m_strName) < (B->m_strName));
    }
    };
    };

    // CPP file
    // Other functions are defined here...
    BOOL CFoo::SortByName()
    {
    std::stable_sort(m_Recs.begin(), m_Recs.end(), NameComparer());

    return TRUE;
    

    }

    Now, basically, I am trying to properly write and use a predicate function (I think that's what they're called; please correct me if I'm wrong) in the context of calling std::stable_sort (and just std::sort for that matter). There are many helpful examples around, but they don't seem to cover dealing with a non-trivial class (or if they do I haven't 'gotten it' yet). In my case, I want to be able to sort the vector of CRec's according to several different CRec member variables (different CStrings, ints, doubles, etc.). My questions are: 1) Did I use proper coding techniques to solve the problem as I have shown here? 2) Is it the case that I need to add additional structs under the private section of CFoo for each comparison CFoo member function I want to write (with the comparisons applied to the std::vector m_Recs and based on the CRec members themselves actually)? 3) Why do I need to wrap the comparison functions in a struct? How does that fact relate to operator(), etc.? Thank you all again for reading and giving any advice, Best, :) Eric

    C / C++ / MFC help c++ graphics question

  • Anyone have a simple line drawing program?
    C Cloaca

    Hi Bill, To answer about the APIs: They are available for your use in a program without creating additional classes, they are supplied as part of Windows and your VC++ 4 compiler should let you write programs that call them. About the includes: To be honest, I'm not sure of the actual #includes needed to access them. The reason is that I take it for granted that they will be provided automatically by App Wizard (the tool provided in VC++) when I create the program skeleton. Are you familiar with using App Wizard to generate a program skeleton? This will help answer about a sample program. Best, Eric

    C / C++ / MFC c++ graphics tutorial question announcement

  • Moving from MFC CList to stl::vector; please help
    C Cloaca

    Diddy, Thanks very much for the reply. I see exactly what you mean. I will try it as soon as I get home where the project is. I appreciate your help! Best, Eric

    C / C++ / MFC c++ help tutorial question csharp

  • Moving from MFC CList to stl::vector; please help
    C Cloaca

    Hi all, I made the following change to the code: I removed the following line (the one with the error): std::vector<CPlayerRec*>::iterator it = initDBM.m_Players.begin(); And I added the following two: std::vector<CPlayerRec*> tempVector = initDBM.m_Players; std::vector<CPlayerRec*>::iterator it = tempVector.begin(); The code now compiles, but I am concerned that I kludged it. Did I just shut the comiler up from bitching or is this the correct solution? If this is correct, then what kind of clean-up do I need to perform regarding tempVector at the end of the copy constructor code? Thanks very much again, :) Eric

    C / C++ / MFC c++ help tutorial question csharp

  • Fatal error
    C Cloaca

    Hi Goh, Have you tried doing a Google search for fltk.lib and link error? This sounds like a custom library and you may need to make sure the linker settings are correct. Also, the tops of included headers may need to have items defined in them. Best, Eric

    C / C++ / MFC help c++

  • Anyone have a simple line drawing program?
    C Cloaca

    Hi Bill, I would say that it depends partly on the OS being used. Is it Windows 9X, NT (or greater), or DOS, etc. If it's Windows, there are API functions available that are as simple to use as: pDC->MoveTo(x1, y1); pDC->LineTo(x2, y2); Which together will draw a line starting at (x1, y1) and ending at (x2, y2). Are you familiar with these kinds of functions? Also, check out http://www.codeproject.com/gdi/[^] If you haven't seen these articles yet, there are a bunch of good ones, and some are marked as 'Beginner'. In particular, check out: http://www.codeproject.com/gdi/dcdrawing.asp[^] Drawing took me some getting used to (I'm also far from a pro programmer) but after a few practice programs you'll get the hang of drawing in Windows. Best, Eric

    C / C++ / MFC c++ graphics tutorial question announcement

  • Moving from MFC CList to stl::vector; please help
    C Cloaca

    Hi there everyone, I'll try to be brief in describing my difficulty. I have been given good advice from this forum that it would be good to learn how to use the STL instead of always using MFC collections like CList. I have been convinced; seeing how many useful tools are available (I'm going to be using stable_sort for example). Here is the deal. My App has a class (CMyDBM) that had as a member a CList as follows: CList<CPlayerRec*, CPlayerRec*> m_PlayerList; Where CPlayerRec is a class that itself holds a fixed number of CStrings and some ints (it has no other classes or structs and nothing dynamic, just some CStrings and ints). I then had a series of functions in CMyDBM that did various things. Among them was the copy constructor function. The project compiled fine at that point. I then removed the CList member from CMyDMB and subsituted the following member: std::vector<CPlayerRec*> m_Players; I changed the copy constructor to the following:

    CMyDBM::CMyDBM(const CMyDBM& initDBM)
    {
    CPlayerRec* ptrPlayerRec = NULL;

    //\*\*\*\*The following line is number 64 in the file (where the error is).
    std::vector<CPlayerRec\*>::iterator it = initDBM.m\_Players.begin();
    
    for(/\*init is above\*/ ; it != initDBM.m\_Players.end(); it++)
    {
        ptrPlayerRec = new CPlayerRec;
        \*ptrPlayerRec = \*((CPlayerRec\*)(\*it));
        m\_Players.push\_back(ptrPlayerRec);		
    }
    

    }

    Now, when I try to build, I get the following error: E:\Program Files\Microsoft Visual Studio\MyProjects\Stats\MyDBM.cpp(64) : error C2440: 'initializing' : cannot convert from 'class CPlayerRec *const * ' to 'class CPlayerRec ** ' Conversion loses qualifiers My idea was to store in the vector a collection of CPlayerRec pointers that I could 'new' as I needed them and then access and delete them later. I am open to storing actual CPlayerRec objects; but then how can I create them 'on the fly' with new and then add them to the vector? I would also have to figure out where / how to delete them. I appreciate you reading this lengthy post and offering any advice. Thanks, Eric

    C / C++ / MFC c++ help tutorial question csharp

  • Is this good form?
    C Cloaca

    Hi Mike, Thanks again. About reason 1.: Most times, the objects that are in a list are made using a call to 'new' at some point in the code. If this is the case, then the contents of the list (the newed objects) need to get deleted at some point anyway. And this must be done by walking through the list in a loop to call delete for each item before doing a RemoveAll() on the list. Or, do you have a methodology in coding that 'recycles' objects. That is, a variable of type CMyObject is declared and reused (has its data changed) whenever an item needs to be added to the list. Then, due to storing actual T's (not T*'s or T&'s), they are passed by reference into the CList by value (so that the declared variable can be changed for reuse to create the next item in the list). Is this what you mean? Does this mean that the destructor for each item in the list is called when the CList is destroyed? Thanks very much, Eric

    C / C++ / MFC question c++

  • Is this good form?
    C Cloaca

    Hi Mike, I appreciate your response. From what you wrote it looks like if I need to maintain a collection of different objects (but all derived from a common base), then a CList< baseclass*, basclass*> is the way to go (which is what I had been thinking for 'my sanity's sake'). For trivially small things (e.g. ints), a CList is good. This sounds good to me. You wrote: "If the objects are larger than about 8 bytes, I use CList< T, const T& > so that any functions which need an object (to store it, or compare it) take their argument by constant reference." What is the advantage of doing CList over CList ? Or, alternatively, is there a reason not to do CList all the time? Thanks again! Eric

    C / C++ / MFC question c++

  • Is this good form?
    C Cloaca

    Thanks for your tip Christian. I will look around to learn how to make std::list (part of the STL, right?) work with MFC (including topics like Serialization, etc.). If you could suggest any resources in particular, that would be great. Thanks again! :-) Eric

    C / C++ / MFC question c++
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups