#include<iostream>
using namespace std;
class Node
{
public:
int data;
Node *preNode;
Node *postNode;
//Node(){}
};
int main()
{
Node testNode;
Node testNodeB = testNode;
return 0;
}
When I run the code, there occurs an runtime error, The variable "testNode" being used without being initiated. But when write an empty constructor, things turns back to normal.
Working Code:
#include<iostream>
using namespace std;
class Node
{
public:
int data;
Node *preNode;
Node *postNode;
Node(){}
};
int main()
{
Node testNode;
Node testNodeB = testNode;
return 0;
}
This code runs without any problem.
Q: Why is this happening?