Errors I can't Figure Out

Hey guys, I am receiving these errors and can't seem to fix them. Help would be very much appreciated!

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Blood::Blood(Vessel vessels[], int vesselCount, int cellCount, int depth)
{
  int **nodePtr = new int[5000]={NULL};
  int src;
  int x = 0;
  for(int i = 0; i < vesselCount; i++)
  {
    nodePtr[i] = new int[2]={NULL};//creating a 2D array off of the primary array
  }//for

  for(int i = 0; i < vesselCount; i++)
  {
    src = vessels[i].src;
    if(nodePtr[src][x][0] != NULL)
      x++;

    nodePtr[src][x][0] = vessels[i].dest;
    nodePtr[src][x][1] = vessels[i].capacity;
  }//for

//printing
 for(int i; i != NULL; i++)
  {
    for(int j; j != NULL; j++)
    {
      cout << nodePtr[i][j][0] << endl;
      cout << nodePtr[i][j][1] << endl;
    }//for
  }//for


//  void print(nodePtr);

} // Blood() 


And here are the error messages I am getting:
g++ -Wall -ansi -g -c blood.cpp
blood.cpp: In constructor 'Blood::Blood(Vessel*, int, int, int)':
blood.cpp:28: error: expected primary-expression before '{' token
blood.cpp:28: error: expected ',' or ';' before '{' token
blood.cpp:33: error: expected primary-expression before '{' token
blood.cpp:33: error: expected `;' before '{' token
blood.cpp:39: error: invalid types 'int[int]' for array subscript
blood.cpp:39: error: 'NULL' was not declared in this scope
blood.cpp:42: error: invalid types 'int[int]' for array subscript
blood.cpp:43: error: invalid types 'int[int]' for array subscript
blood.cpp:47: error: 'NULL' was not declared in this scope
blood.cpp:51: error: 'cout' was not declared in this scope
blood.cpp:51: error: invalid types 'int[int]' for array subscript
blood.cpp:51: error: 'endl' was not declared in this scope
blood.cpp:52: error: invalid types 'int[int]' for array subscript
make: *** [blood.o] Error 1

Thanks in advance!
Im almost a complete newb But i may be able to solve some of your problems...about the NULL, you should be able to subsititute that for false. cout and endl only work when you include iostream.h. some compilers (like DevC++) dont accept that unless you use the std namespace.hope this helps...
To fix the cout errors, try adding this to the top of the file (no ".h" after iostream):

1
2
3
#include <iostream>
using std::cout;
using std::endl;

This declaration is not correct:
 
int **nodePtr = new int[5000]={NULL};


From the code, it seems like you want a three dimensional array, but it's declared as two dimentional, and allocated as one dimentional. The ={NULL} initialization is not allowed here, only when you allocate on the stack (e.g. "int* nodePtr[5000] = {0};")

I can't really help you anymore without a description what you try to do with Vessel::src and x.

Maybe you should try using std::vector, and maybe you need to do something like
 
nodePtr[src * CONSTANT + x][0] = ...
Thanks a lot guys. I actually decided to change from a 3D array to an array in which each index points to a linked list. This is what I have gotten so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class listNode
{//line 17
public:
  listNode(){}
  listNode(int dest, int cap, listNode* ptr)
             :destination(dest), capacity(cap), pointer(ptr){}
  listNode* getPtr() const {return pointer;}
  int getDest() const {return destination;}
  int getCap() const {return capacity;}
  void setPtr(listNode* link){pointer = link;}
  void setDest(int dest){destination = dest;}
  void setCap(int cap){capacity = cap;}

private:
int destination;
int capacity;
listNode *pointer;
};//listNode

class arPtr
{
public:
  arPtr(int amt, listNode* Ptr):amount(amt)
  {
    //typedef listNode* arPtr;
    for(int i = 0; i < amt; i++)
      Ptr[i] = new listNode(-1, -1, '\0');//line 42
  }//arPtr constructor

private:
  int amount;
  listNode* Ptr;
};//class arPtr 


These are the errors that I get:
1
2
3
4
5
g++ -Wall -ansi -g -c blood.cpp
blood.h: In constructor 'arPtr::arPtr(int, listNode*)':
blood.h:42: error: no match for 'operator=' in '*(((listNode*)(((unsigned int)i) * 12u)) + Ptr) = (((listNode*)operator new(12u)), (<anonymous>->listNode::listNode(-0x000000001, -0x000000001, 0u), <anonymous>))'
blood.h:17: note: candidates are: listNode& listNode::operator=(const listNode&)
make: *** [blood.o] Error 1


Basically what I want to do is make arPtr be an array. I want every index of arPtr to point to a linked list(listNode). I am trying to make a constructor but am having a very hard time. Anyone that can help please do! I really appreciate it!
Topic archived. No new replies allowed.