Pointers and Dynamic Array Help

closed account (9hX8C542)
So I'm supposed to write a function in class called ArrayList. Two of the functions have to deal with finding the first element of the container. One is just a constant version of the other. The protected members of the class are:

protected:
int *m_list; ///< Pointer to dynamic array.
std::size_t m_capacity; ///< Physical size of dynamic array.
std::size_t m_size; ///< Number of array elements in use.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    /// @brief Returns a reference to the first element in the container.
    /// Calling front on an empty container is undefined.
    /// @return Reference to the first element.

    int& front() { return *begin(); }
    const int& front() const { return *begin(); }

    int& ArrayList::operator[](std::size_t pos)
    {
       return front();
    }

    const int& ArrayList::operator[](std::size_t pos) const
    {
       return front();
    }


This is worse than usual lol, when I usually post here, it's for debugging, but I'm completely lost on this one guys. The brief statement is all the instruction I get on it too, so interpret at will. But it has to follow those outlines. Thanks for any help you can give. Sorry I'm so lost.
So what exactly is your problem?


Two of the functions have to deal with finding the first element of the container.
Well, yes, so they do. They call front(). Do you mean you want to do something else with these functions ... like overload []?
Last edited on
what is this going to be. you can put a list in an array/vector rather than fool with dynamic memory. Is that what this is?
Topic archived. No new replies allowed.