|
-
July 1st, 2009, 04:15 AM
#1
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.
-
July 1st, 2009, 04:27 AM
#2
Re: Does this call create a list automatically?
 Originally Posted by hajimeml
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
-
July 1st, 2009, 07:25 AM
#3
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)
:
};
-
July 1st, 2009, 08:12 AM
#4
Re: Does this call create a list automatically?
I´m wondering how it compiles at all There must be some intermediate code missing...
- Guido
-
July 1st, 2009, 08:25 AM
#5
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.
-
July 1st, 2009, 08:50 AM
#6
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
-
July 1st, 2009, 10:40 AM
#7
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
-
July 1st, 2009, 07:44 PM
#8
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.
-
July 3rd, 2009, 07:17 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|