Can't get rid of the errors

Getting a couple errors with my program.
|23|error: no match for 'operator=' in '((MyStack<char>*)this)->MyStack<char>::list = (operator new(12u), (<statement>, ((MyLinkedList<char>*)<anonymous>)))'|
|85|error: invalid conversion from 'Node<char>*' to 'char' [-fpermissive]|
|31|error: initializing argument 1 of 'Node<T>::Node(T) [with T = char]' [-fpermissive]|
1
2
3
4
5
6
  template <typename T>
MyStack<T>::MyStack(){

   list = new MyLinkedList<T>(); //line 23
}
template <typename T>

1
2
3
4
5
6
7
8
9
10
11
12
13
template <typename T>
void MyLinkedList<T>::add(T val){

     Node<T> current = head;
     Node<T> add = new Node<T>(val); //line 85


        while (current.getNext() != NULL){
               current = *(current.getNext());
        }

        current.setNext(new Node<T>(val));
}

1
2
3
4
5
6
template <typename T>
 Node<T>::Node(T data){  //line31

    value = data;
    next = NULL;
}

Last edited on
Node<char> add( new Node<char>(val) );
Yes, you do create object add, which is a Node<char> and naturally call its constructor: Node<char>::Node( char ). The new returns a pointer. How should one make a char out of a pointer?


You did not show the type of MyStack<T>::list but I bet that ain't a pointer either.
To add to keskiverto's sound advice,

Here is a couple of nice tutorials to help you out:
https://www.tutorialspoint.com/cplusplus/cpp_pointers.htm
http://www.cplusplus.com/doc/tutorial/pointers/

Hope this helps you to understand keskiverto's sound advice,

~Hirokachi
Since I am adding a node, I know I need to be able to read the position of the node, but I am not really sure how to do that. I've read the tutorials and I am just not getting it. This is what I think my 85 should look like.
 
Node<T> *add(new Node<T>(val));

New error message says "warning: unused variable 'add' (-Wunused-variable)
Last edited on
I changed line 23 to
 
list = *(new MyLinkedList<T>());

The code will run and as soon as command prompt opens, it will crash.
Topic archived. No new replies allowed.