View Single Post
Old Jan 16th, 2006, 3:46 AM   #1
Yona
Newbie
 
Join Date: Jan 2006
Posts: 2
Rep Power: 0 Yona is on a distinguished road
invalid conversion from `const IntNode*' to `IntNode*'

hi,
i am working on this assignment. i have a header IntNode given and based on this header i have to make a new header InrNodeEx in which i have to make the three following functions :
-inline int list_sum(const IntNode *head)
Returns sumary of list
-inline void list_multilpy_withNumber(IntNode *head, int number)
Multiplies all elements of list with a number
-inline IntNode* list_from_multiplyWithNumber(const IntNode* source, int number)
Multiplies all elements of list with a number without changing the source list
IntNodeEx i've written is the following
#include "IntNode.h"

//Returns sumary of list 
inline int list_sum(const IntNode *head){ 
IntNode *current; 
int sum=0; 
current=head; //ERROR APPEARS HERE//
while(current){ 
sum = sum + current->data; 
current=current->getNext(); 
} 
return sum; 
} 


//Multiplies all elements of list with a number 
inline void list_multilpy_withNumber(IntNode *head, int number){ 
IntNode *current=head; 
while(current){ 
current->data=(current->data)*number; 
current=current->getNext(); 
} 
} 

//Multiplies all elements of list with a number without changing the source list 
inline IntNode* list_from_multiplyWithNumber(const IntNode* source, int number){ 
IntNode *current=source; //ERROR APPEARS HERE//
IntNode *target=0; 
while(current){ 
list_insert(&target, new IntNode((current->data)*number)); 
current=current->getNext(); 
} 
return target; 
}

the problem is that when i call the functions list_sum(const IntNode *) and list_from_multiplyWithNumber(const IntNode*, int) the compiler shows the following mistakes
In function `int list_sum(const IntNode*)':nvalid
conversion from `const IntNode*' to `IntNode*'
In function `IntNode* list_from_multiplyWithNumber(const IntNode*, int)':invalid conversion from `const IntNode*' to `IntNode*'
which is absolutely normal to happen but i really can't figure out any way to deal with these errors.

Can anybody suggest any solution?
thanx for ur time!!!!
Yona is offline   Reply With Quote