linked list stack error?

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
struct StackItem
{
string name;
StackItem *next; 
};

typedef StackItem* nodePtr;

class Stack
{
private:

int numElements;
nodePtr top; 
int count; // used for print count in recursive function

public:

a bunch of functions here that work, then theres this one

void push (StackItem *newItem)
{
newItem->next = top;
top = newItem;
nodePtr p, prev = nullptr;
p = new StackItem;
p->name = newItem; //this is the one i keep getting errors on
numElements++;
linkNodeByAcctNum(p, prev);
}


ok so this is my code for a function that will push or add a new item to the stack, for some reason i keep getting an error about that line saying "no viable overload '='" can anyone tell me what this means? (its the third last, i added a comment saying errors)
thanks!
Aren't you trying to assign a StackItem* to a string? I think the error message means that you don't have an overload of operator= that takes a StackItem* as parameter
Last edited on
i was just supposed to do
p->name = newItem->name;
instead
p->name = newItem;
haha wow i dont feel smart right now
Topic archived. No new replies allowed.