CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2009
    Posts
    30

    Does this call create a list automatically?

    Hello. Could anybody please clarify?

    I came across a file called GGen.cpp. Inside it, there is a statement:

    int i,j,nos = GetNumOfSteps();

    I guess only nos is initialized to a value returned from GetNumOfSteps().

    In GGen.h, things are defined as follows:

    int GetNumOfSteps(void) const {
    return CListManager<CStep>::GetNumOfItems();
    }

    Then, inside the file ListManager.h, I found:

    private: list <T*> items;
    public: virtual int GetNumOfItems(void) const { return items.size(); }

    I guess the first line creates a private list named "items" of type CStep and
    the second line gets the number of elements in this list. Am I Right?

    When nos=GetNumOfSteps() is executed, the size of WHAT is going
    to be returned? Does this call creates a list implicitly? As GGen.cpp
    and ListManager.h are different files, I don't think this statement returns
    the number of elements in the list "items". I am confused.

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Does this call create a list automatically?

    Quote Originally Posted by hajimeml View Post
    int GetNumOfSteps(void) const {
    return CListManager<CStep>::GetNumOfItems();
    }
    It looks like CListManager<CStep> has a static method GetNumOfItems which needs no object to be called on. Please post the CListManager<CStep>::GetNumOfItems() method body to see what object is used.
    - Guido

  3. #3
    Join Date
    Apr 2009
    Posts
    30

    Re: Does this call create a list automatically?

    Thanks, GNiewerth.

    I only found:

    template <class T>
    class CListManager
    {
    private:
    list<T*> items;
    public:
    virtual int GetNumOfItems (void) const { return items.size(); }
    :
    (stuffs removed)
    :
    };

  4. #4
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Does this call create a list automatically?

    I´m wondering how it compiles at all There must be some intermediate code missing...
    - Guido

  5. #5
    Join Date
    Apr 2009
    Posts
    30

    Re: Does this call create a list automatically?

    There are hundreds of files in the project but as far as I am aware of, there is only one definition of GetNumOfItems in CListManager. Searching the class explorer in Borland Builder C++ also returns only this method.

  6. #6
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Does this call create a list automatically?

    Another solution came to my mind:

    Is it possible that GetNumOfSteps() is a member of a CListManager<CStep> derived class? In that case GetNumOfSteps() calls GetNumOfItems of its parent class.
    - Guido

  7. #7
    Join Date
    Apr 2009
    Posts
    30

    Re: Does this call create a list automatically?

    Thanks for the suggestion, GNiewerth. I found that in GGen.h,

    class CGGen : private CListManager<CStep>, public COtherClass

  8. #8
    Join Date
    Apr 2009
    Posts
    30

    Re: Does this call create a list automatically?

    As far as I know, due to the private inheritance relationship mentioned in the previous post, all public members of the base class CListManager become private members of class CGGen. However, CGGen cannot access the list named "items" defined in ListManager.h because this list is defined as private in the base class CListManager.

    So, could you please let me know why in GGen.h, the GetNumOfStep(void) const function uses:

    return CListManager<CStep>::GetNumOfItems()

    instead of

    return GetNumOfItems()

    I though the public member function GetNumOfItems() became a private member function of CGGen already.

    Q1: Is it because in order to access the private member "items" defined in ListManager.h,
    it has to be done this way?

    Q2: In this case, the inherited member function GetNumOfItem() in GGen.h is not used.
    Am I right?
    Last edited by hajimeml; July 3rd, 2009 at 07:13 PM.

  9. #9
    Join Date
    Apr 2009
    Posts
    30

    Re: Does this call create a list automatically?

    Sorry there was a typo in the class name. Could anybody please check my understanding?
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured