Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
share|improve this question
    
What is List supposed to do and what is Graph supposed to do? –  rwols Jul 2 '13 at 20:48

2 Answers 2

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];
share|improve this answer
    
Fixed it for me. Thanks! –  user1754267 Jul 2 '13 at 20:52

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

lists = new List*[listCount];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.