I have this class in Python that I am trying to recreate in C++,
class Node:
def __init__(self, data = None, next = None):
self.data = data
self.next= next
So far I have constructed this in C++,
.h
#include<stdlib.h>
#include <iostream>
class Node {
public:
int value;
Node* next;
Node(int value, Node next) : value(0), next(NULL){
std::cout << "inside .h" << "\n";
};
};
and .cpp
Node::Node(int value, Node next) {
this->value = value;
this->next = &next;
}
The code itself confuses me, it is usually best practice to avoid writing methods inside the .h but it wouldn't let me set the default values without {...}, i.e. I could not type Node(int value, Node next) : value(0), next(NULL); which I initially expected. It seems that I have defined two constructors aswell, which seems odd given the same parameters.
inside main it is not allowing me to instantiate an object as Node(5) etc...
Do we have a new way in C++ to mimic the Python class above?