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;
}
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.
Comments