Alas, I cannot get these types to agree...

I believe that the problem here is making the types agree, however, I am not sure how to do this. I have tried creating this little problem four different ways, and I am afraid I am missing some little detail that won't allow it to run. The error C2664 comes up where I am trying to dereference the pointers, but the types don't agree...? This should not be so complex! I am sure an experienced eye will see what I am doing wrong.

Code:
#include <iostream>
using namespace std;

int main()
{
struct node;
typedef node *ptrType;
struct node
{
int Data;
ptrType next;
};

ptrType nodeA = new node(1);
ptrType nodeB = new node(2);
ptrType nodeC = new node(3);
ptrType cur = new node;
ptrType head = new node;

*nodeA = 1;
*nodeB = 2;
*nodeC = 3;

head->next = nodeA;
nodeA->next = nodeB;
nodeB->next = nodeC;
nodeC->next = NULL;
cur = head->next;

for (int i = 1; i <=3; i++)
{
if(cur->next != NULL)
{
cur = cur->next;
cout << cur << " " << endl;
}
else break;
}

return 0;
}
What is error C2664?

What line does the error happen on?
I think I figured it out. You are awesomely fast, though. I was not including the Data item in the struct to take the value. The error is that the types ptrType and int weren't agreeing. Sorry. Worked on this for hours and between the time I posted and now found the solution. Here it is:


#include <iostream>
using namespace std;

int main()
{
struct node;
typedef node *ptrType;
struct node
{
int Data;
ptrType next;
};

ptrType nodeA = new node;
ptrType nodeB = new node;
ptrType nodeC = new node;
ptrType cur = new node;
ptrType head = new node;

nodeA->Data = 1;
nodeB->Data = 2;
nodeC->Data = 3;

head->next = nodeA;
nodeA->next = nodeB;
nodeB->next = nodeC;
nodeC->next = NULL;
cur = head->next;

for (int i = 1; i <= 3; i++)
{
cout << cur->Data << " " << endl;
cur = cur->next;
}

return 0;
}

Stay tuned, though! I will have many more questions. Thanks again for responding so quickly!
Last edited on
Topic archived. No new replies allowed.