so far my program works fine but I keep getting one error which is:
error C2440: 'return' : cannot convert from 'int [5]' to 'int'
1> There is no context in which this conversion is possible
I bet your compiler does mention a line-number. 75, 79, 86.
You state that the return value is an int. You attempt to return an array. If you want to return an array, then you have to pass it to the function as parameter.
int ListStack::get_value(int c)
{
/* bla bla */
for (i=0;i<=operand_count;i++)
{
cout<<"Enter Value: ";
cin>>numeric_array[i];
return numeric_array; // this is your error
}
}
you are returning an array ( which is i think illegal ) but you only have declared the return type of get_value() as an int
I'm not sure if you want to return a value one by one, and if so, you have to use static keyword otherwise the data will just be loss.
Or i am not also sure if you want to return an array which is i think illegal but,
you can return a pointer to the array or pass the array as parameter instead
Thank You for your response, ive tried fixing that error and now I get these error messages:
warning C4715: 'ListStack::pop' : not all control paths return a value
warning C4715: 'ListStack::get_value' : not all control paths return a value
here is pop()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int ListStack::pop()
{ int c;
if(top==NULL)
cout<<"Stack UnderFlow"<<endl;
else
{
node *temp;
temp=top;
cout<<"deleted Number from the stack = ";
c=top->num;
top=top->next;
return (temp->num);
delete temp;
return (c);
}
}
and here is getValue()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int ListStack::get_value(int c)
{ int operand_count;
cout<<"how many number of operands you have?";
cin>>operand_count;
int numeric_array[5];
int i;
for (i=0;i<=operand_count;i++)
{
cout<<"Enter Value: ";
cin>>numeric_array[i];
return numeric_array;
}
}
get_value() has a loop. If operand_count is less than zero, nothing is returned. If operand_count is zero or more, numeric_array[0] is shown and then you attempt to return the address of a local array (which is an error too). What is your actual intention?
int ListStack::pop()
{
int c;
if (top==NULL)
cout << "Stack UnderFlow"<<endl;
return 0; // return some integer value - doesn't have to be 0
else
{
node *temp;
temp = top;
cout << "deleted Number from the stack = ";
c = top->num;
top = top->next;
return (temp->num); // function exits here
delete temp; // this line is never executed
return (c); // this line is never executed
}
}
I pointed out that there were two return statements, and that code after the first one will never be executed. But that doesn't mean you should simply erase those lines. In particular, line 15, delete temp;. This delete should be matching a previous use of new in the function push()
As a general principle, each use of new should be exactly balanced by a corresponding delete, in order to avoid memory leaks.