Im very new to c++, so I will need some help for this. Here is the code:
RootNode.h
#ifndef ROOTNODE_H
#define ROOTNODE_H
class RootNode
{
public:
int getNodeId();
void setNodeId(int i );
protected:
private:
int node_id;
};
#endif // ROOTNODE_H
RootNode.cpp
class RootNode{
private:
int node_id;
RootNode()
{
//ctor
this->setNodeId(0);
}
void setNodeId(int i ){
node_id = i;
}
int getNodeId(){
return node_id;
}
~RootNode()
{
//dtor
}
};
main.cpp
#include <stdio.h>
#include <iostream>
#include "LeafNode.h"
#include "DecisionNode.h"
#include "RootNode.h"
using namespace std;
int main(int argc, const char* argv[]){
RootNode rootNode;
cout<<rootNode.getNodeId();
return 0;
};
I get this error when I try to compile with g++:
$ g++ RootNode.cpp main.cpp
/tmp/ccylUcLS.o: In function `main':
main.cpp:(.text+0x17): undefined reference to `RootNode::getNodeId()'
collect2: error: ld returned 1 exit status
I have looked online, but I really dont understand what goes wrong. I have also tried to build with CodeBlocks, but its of no use.
Thank you!