![]() |
| | #1 |
| Registered User Join Date: Apr 2008
Posts: 75
| Problem with pointers I have the basic struct Code: typedef struct Node
{
Data* data;
struct Node* next;
} No;
Code: void insert (Node* node)
{
Node* tmp, tmpProx;
if (head == NULL)
{
head = node;
}
else
{
for(tmp = head; tmp->next != NULL || calcDist(tmp->next->restaurante) > calcDist(no->restaurante) ; tmp = tmp->next );
// Problem Here!
tmpProx = tmp->next;
tmp->next = node;
node->next = tmpProx;
// End of Problem
}
}
Code: error: incompatible types in assignment |
| kotoko is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,785
| Code: Node* tmp, tmpProx; tmp is of type Node*, but tmpProx is of type Node. To solve it, do either: Code: Node *tmp, *tmpProx; Code: Node* tmp; Node* tmpProx;
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Technical Lead Join Date: Aug 2007 Location: London, UK
Posts: 723
| That's because you've committed one of the cardinal sins of declaring pointers! When you write: Code: int * a, b; Code: int * a; int b; My recommendation is always to declare and initialise variables on their own line, i.e. Code: Node * tmp = NULL; Node * tmpProx = NULL; Edit: Damn you Elysia
__________________ "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support "Have you tried turning it off and on again?" - The IT Crowd Last edited by QuantumPete; 06-12-2008 at 04:54 AM. Reason: lack of proper touch typing skills |
| QuantumPete is offline | |
| | #4 |
| Registered User Join Date: Apr 2008
Posts: 75
| Thank YOU! Oh my God! I would never remember to check that in a million years! Thank you so much! |
| kotoko is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hi , i'm having a problem with pointers in C ... | blackslither | C Programming | 2 | 10-26-2008 03:57 AM |
| Problem with file handling (pointers) | hmk | C Programming | 5 | 09-19-2008 10:03 AM |
| A problem with pointers | vsla | C Programming | 2 | 10-10-2007 04:14 AM |
| Returning pointer to array of pointers problem | jimzy | C Programming | 15 | 11-11-2006 06:38 AM |
| Problem writing swap using pointers | joshdick | C++ Programming | 1 | 02-29-2004 10:06 PM |