I have made a wery simple program but i still get a linker error
I have one class

ifndef Node_H
#define Node_H
#include <iostream>
using namespace std;

//class node has four fields: type, child1, child2 and parent. The type is -1 if it is a inner node, 0 if it is the root and a positive number (cooresponding to the item it represent) if it is a leaf. The leaves functions eighter returns or changes it fields.

class Node{
    int type_;
    int inter1_;
	int inter2_;
	int length_;
	Node* child1_;
    Node* child2_;
    Node* parent_;


	Node(Node* n1, Node* n2, int t);
	int getLength(){
		return length_;
	void setLength(int i){
		length_ = i;
	int getInter1(){
	return inter1_;
	int getInter2(){
		return inter2_;
	void setInter1(int i){
	void setInter2(int i){
	int getType(){
      return type_;

    Node* getChild1(){
      return child1_;

    Node* getChild2(){
      return child2_;

    Node* getParent(){
      return parent_;
	void setType(int i){
	void setChild1(Node* n){

    void setChild2(Node* n){

    void setParent(Node* n){
	void printNode(){
      cout << "type: " << getType()<< " inter1: "<< getInter1()<< " inter2: "<< getInter2() <<endl;  

#include "Node.h"
Node::Node(Node* n1, Node* n2, int t){
    child1_ = n1;
      child2_ = n2;
      type_ = t;
      parent_ = NULL;
    inter1_= 1000;

and master.cpp
#include "Node.h"
int main(){
	cout << "something"<< endl;
  int z=0;
  Node* n;
  Node p(NULL,NULL,z);
	int stop;
	cin >> stop;
	return 0;

I get the following error:
Master.cpp:(.text+0xcc): undefined reference to `Node::Node(Node*, Node*, int)'
If I move my the text form Node.cpp to Node.h I dont get the error. Can anybody tell me what is wrong??

Edited 6 Years Ago by Nick Evan: Added CODE-tags

How are you compiling? Do you use an IDE?
It seems that Node.cpp isn't being compiled (e.g. no Node.o is created).

I use linux here is my makefile

# makefile

some: Master.o
	g++ -o Prog Master.o

Master.o: Node.o
	g++ -Wall -c Master.cpp

Node.o: Node.cpp Node.h
	g++ -Wall -c Node.cpp

	rm *.o
	rm *~ 

Edited 6 Years Ago by Nick Evan: Added tags

Not sure what the problem is but you should never have this in a header file

using namespace std;

Also this line in your makefile

Node.o: Node.cpp Node.h

Why Node.h? Its already in the includes right?

Edited 6 Years Ago by gerard4143: n/a

This article has been dead for over six months. Start a new discussion instead.