I'm getting the error:
taking address of rvalue [-fpermissive]
31 | ListNode l = ListNode(2, &ListNode(4));
when executing the following code:
#include<iostream>
class ListNode {
public:
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
int main(){
ListNode l = ListNode(2, &ListNode(4));
return 0;
}
I don't really know how to use classes in C++ but I would like to use a Class here for the LinkedList instead of a struct.