On Apr 17, 11:17 am, shanknbake <firedhi...@gmail.comwrote:
I'm getting the following compile-time error:
error C2352: 'Person::getCount' : illegal call of non-static member
function
Here is my getCount function declaration:
-----------------------------------------------------------------------------------
//person.h
class Person
{
....
public:
...
int getCount();}
----------------------------------------------------------------------------------
//person.cpp
int Person::getCount()
{
return count;}
----------------------------------------------------------------------------------
//test.cpp
int main()
{
...
for (int i = 0; i < Person::getCount(); i++)
persPtr[i]->print();
Where is persPtr declared? And what is its relationship with
Person::getCount()? A priori, what you need in the for loop is
something like:
for ( int i = 0 ; i < numberOfElementsIn_persPtr ; ++ i ) {
persPtr[ i ]->print() ;
If Person::getCount() is supposed to track the number of
elements in persPtr, and those elements are of type Person*
(just a guess), it should be static. But it seems a very
strange organization; I would not expect a class Person to know
about the number of elements in some array unless it also
managed that array.
int total = Person::getCount();
...}
-----------------------------------------------------------------------------------
Do you see something that I don't?
Probably lots of things, but without seeing more, it's hard to
say what is relevant. Other's have addressed the issue of
static functions, in isolation, but I wouldn't be surprised if
the problem isn't at a higher level. What is persPtr: what is
its role and its responsibilities in the total program, and who
manages it?
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34