Hi!
I don't understand why I can't use my functions declared like this:

#include "groundArray.h"

int groundArray::getlistX(int i)
{
 return x;
}
int groundArray::getlistY(int i)
{
    int groundlistY[] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
    return groundlistY[i];
}
int groundArray::getlistWidth(int i)
{
    int groundlistWidht[] = {40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40};
    return groundlistWidht[i];
}
int groundArray::getlistHeight(int i)
{
    int groundlistHeight[] = {40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40};
    return groundlistHeight[i];
}

With the header file

#ifndef GROUNDARRAY_H

#define GROUNDARRAY_H





class groundArray

{

    public:

        groundArray();

        virtual ~groundArray();

        static int getlistX(int i);

        static int getlistY(int i);

        static int getlistWidth(int i);

        static int getlistHeight(int i);
        const static int x = 89;

    protected:

    private:

};
#include "masterList.h"

#include "groundArray.h"



int* masterList::list(void)

{

    int* pointer;

    int list[size*2];

    pointer=list;

    for(int i = 0; i<size; i+=2)

    {

       list[i] = getlistX(i);

       list[i+1] = getlistY(i);

    }

    return pointer;

}

int masterList::getSize(void)

{

    return size;

}

I get the error message: masterList.cpp|11|error: ‘getlistX’ was not declared in this scope|. Why?

MasterList is supposed to make the coordinates for the ground available as an array within main() later.

Recommended Answers

All 2 Replies

Because you are working in the source code of the class "masterList"...

the only way "masterList" would be able to access the functions of "groundArray" is by creating an instance of it (groundArray * ground = new groundArray())

and then calling its methods as follows: ground->getlistX(i)

another way would be to inherit "masterList" from "groundArray"

Member Avatar for MonsieurPointer

Since you are calling static functions, you will need to supply your class name. Therefore, you need to make calls like groundArray::getlistX, groundArray::getListY, etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.