Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   What does *pointer_to_class means? (http://www.go4expert.com/forums/pointertoclass-means-t18315/)

hajimeml 3Jul2009 07:23

What does *pointer_to_class means?
 
Hello. I am trying to understand a program. In class CGG, there is a definition:

CPGE *PGE;

I guess it means that PGE is a pointer to class CPGE. Inside the class CPGE, there is a member function called RSFPtr(). Inside class CGG, there is a statement:

(*PGE->RSFPtr())[i] = TempRFState[i];

As far as I understand, PGE->RSFPtr() means calling the member function RSFPtr(). The above statment is different. Could you please let me know what it means?

SaswatPadhi 3Jul2009 12:34

Re: What does *pointer_to_class means?
 
When I saw your question, what immediate came to my mind is that .. the function RSFptr() must be returning pointer to an array and so the statement (*PGE->RSFPtr())[i] = TempRFState[i]; assigns TempRFState[i] to the i'th element of that array.

Try to run the following test code for further clarification :
Code: C

#include <stdio.h>

#define SIZE 1000
class Test
{
    private:
        int Array[SIZE];

    public:
        int* AccessArray()    {   return Array;   }
};

int main()
{
    Test ClassA;
    Test* pClassA = &ClassA;

    for(int i = 0; i < SIZE; ++i)
        (pClassA->AccessArray())[i] = i;

    for(int i = 0; i < SIZE; ++i)
        printf("%u\n", (pClassA->AccessArray())[i]);

    return 0;
}


There might be some other meaning of (*PGE->RSFPtr())[i] = TempRFState[i];
If I find any other meaning, I'll update this thread :)

hajimeml 3Jul2009 14:58

Re: What does *pointer_to_class means?
 
Thanks for the help. Do you mean the * dereference operator in front of PGE returns to the address of the first element of the array and the [i] moves the pointer to the ith element of the array? When i=0, *PGE just points to the first element of the array?

SaswatPadhi 3Jul2009 17:36

Re: What does *pointer_to_class means?
 
>> Do you mean the * dereference operator in front of PGE returns to the address of the first element of the array and the [i] moves the pointer to the ith element of the array? When i=0, *PGE just points to the first element of the array?

Yes, that's what I meant ! :)

>> Thanks for the help
My pleasure !

hajimeml 3Jul2009 21:25

Re: What does *pointer_to_class means?
 
Thanks again.


All times are GMT +5.5. The time now is 00:00.