2021-12-01

meaning of "nonstatic member reference must be relative to a specific object" when trying to reference an array within a member function

I am confused as to why I am unable to use arrValues, valuesBegin, and valuesEnd despite my member function being publicly defined within a class which is a predecessor of ArrayValues.

I have the following code which is giving me trouble:

struct algorithms
{
    class arrayAlgs
    {
    public:
        int arrValues[100];
        int* valuesBegin = std::begin(arrValues);
        int* valuesEnd = std::end(arrValues);

        class ArrayValues
        {
        public:

            void createRandomArrayValues(){
            for(int& i: arrValues)
            {
                i = rand() % 100;
            }

        }
             void createAscendingArrayValues()
        {
                for(int* i = valuesBegin, d = 1;i <= valuesEnd; i++, d++)
            {
                *i = d;
            }
        }
        };
};
};

The following code is a class which stores algorithms but within it it has two member functions which create the environment for the algorithms to be used within, however this results doesn't build due to errors stating:

"A non-static member reference must be relative to a specific object"

I am unsure of what this really means and how I can adapt my code without changing the variables so that the program runs smoothly.



from Recent Questions - Stack Overflow https://ift.tt/3d7tt74
https://ift.tt/eA8V8J

No comments:

Post a Comment