I need to convert an int parameter into a linked list field

Henji

I created a link list and an integer field to represent the linked list. Then I assigned the integer field to 0. I don't know how to convert the int parameter into the linked list.

template<typename T>
struct Node{
  T data;
  Node* next;
};

class Integer{
private:
  Node<int>* real_num;

public:
    
Integer(){
   real_num->data = 0;
   std::cout << "success!";
}

Integer(int int_convert){
   real_num->data = int_convert;
}
Stephen Duffy

The constructor assigns a value to a variable in a structure which has been declared but not itself constructed.

Add this to the top of your constructors.

Node<int> * real_num=new Node<int>;

Only after the Node has had memory allocated, etc is it valid to reference a variable in the struct that real_num only points to. Without 'new' real_num points to null.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I need to convert an int variable to double

Why can I assign an int to a Short for return type but not in parameter list?

How can I convert comma separated string into a List<int>

Convert List<int?> to List<int>

Nil:List[Int] as parameter

Convert Tibble to Parameter List

How do I convert a string to a list of Maybe Int

Need help visualizing a linked list

How can I convert a text file into a list of int arrays

Can I convert a tuple to a parameter list 'inline'?

Convert linked list to tree in Java

Singly Linked List swap function (int, int)

What is the need for asymmetric linked list

Pop method for doubly linked list implementation in C, do I need to use free

How to convert sql server field size to vb.net (My need is to specify parameter size against sql server field)

How do I convert int(input) into a list

I believe I need a small increase in code quality in the code I have written for Double Linked List

How can I get a total count of an int field in a List?

I need to convert this string into a list in Python

Need to convert the field to datetime

Error 'int' object is not subscriptable, How do i convert it to list?

how i can convert from int[] to List<Integer> in java

I don't understand the need of these conditions. How and when can a linked_list be None?

Why do I need to make 'head' equal to 'prev' to finish reversing a Linked List?

Is there a way I can convert a list of string into a list of int in python/flask?

Why do I need to convert from Integer[] to int[]?

I need to convert a javascript array to a sql list

*i was trying to add elements in a linked list in python but i am getting TypeError: '>' not supported between instances of 'int' and 'NoneType

I need a list of Date and time in "hh:mm a" format from the list the List<int> flutter