I have made a wery simple program but i still get a linker error
I have one class
Node.h
#

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{
  private:
    int type_;
    int inter1_;
	int inter2_;
	int length_;
	Node* child1_;
    Node* child2_;
    Node* parent_;

  public:

	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){
	inter1_=i;
	}
	void setInter2(int i){
	inter2_=i;
	}
	int getType(){
      return type_;
    }

    Node* getChild1(){
      return child1_;
    }

    Node* getChild2(){
      return child2_;
    }

    Node* getParent(){
      return parent_;
    }
    
	void setType(int i){
      type_=i;
    }
    
	void setChild1(Node* n){
      child1_=n;
    }

    void setChild2(Node* n){
      child2_=n;
    }

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

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

}
;
and master.cpp
#include "Node.h"
int main(){
	cout << "something"<< endl;
  int z=0;
  Node* n;
  Node p(NULL,NULL,z);
  p.printNode();
	
		
	
	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??

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

[b]
# 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

clean:
	rm *.o
	rm *~ 
[/b]

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.