mardi 23 février 2021

C++ creating a new object of class?

I was given the following details about a data structure:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     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) {}
 * };
 */

How can I probably create a new ListNode and a pointer to it?

I tried:

ListNode *result=ListNode(10);

but didn't work

Aucun commentaire:

Enregistrer un commentaire