4

Having trouble initializing these custom (not STL) List objects with the following implementation. The Graph class contains an array of pointers to custom List objects. I'm pretty sure I went somewhere wrong with how I declared my lists array.

Snippet of header:

class Graph
{
    private:
        List **lists;
        int listCount;
    public:
        .......
        .......
}

Snippet of implementation:

//node integer is used for size of array
void Graph::setLists(int node)
{
    listCount = node;
    lists = new List[listCount];

    //for is used to initialized each List element in array
    //The constructor parameter is for List int variable
    for(int i = 0; i < listCount; i++)
        lists[i] = new List(i);
}

Errors I'm getting:

Graph.cpp: In member function ‘void Graph::setLists(int)’:
Graph.cpp:11:28: error: cannot convert ‘List*’ to ‘List**’ in assignment
1
  • What is List supposed to do and what is Graph supposed to do? Commented Jul 2, 2013 at 20:48

2 Answers 2

4

The only problem I see is that you are trying to initialize lists with with an array of List objects instead of an array of pointers to List objects.

change

lists = new List[listCount];

to

lists = new List*[listCount];
Sign up to request clarification or add additional context in comments.

Comments

0

Because you are creating an array of List objects, and not an array of List pointers.

lists = new List*[listCount];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.