Hi,
I believe I am defining the tree structure multiple times and this is causing problems. I have tried to correct for this but not with any success. Was wondering if some would take a look and see what the issue might be?
There are three files to consider here. The Myheader.h file, The Myroutines.cpp file and Main.cpp. Both Myroutines.cpp and Main.cpp reference the Myheader.h file. The error is get is of the following type:
MyRoutines.obj : error LNK2005: "public: void __thiscall tree::make_tree(int,int)" (?make_tree@tree@@QAEXHH@Z) already defined in main.objHere make_tree is a routine that is defined as part of the tree class. It is defined in the Myheader.h file. That file is included in main.cpp and Myroutines.cpp.
I) snippet of Code in Myheader.h:
#ifndef _MY_HEADER_
class node{
/* some code here defininng the node class */
};
class tree{
public:
int size,nl,nh;
node **p; void make_tree(int ml, int mh); tree(){size=0; p = new node*[0];}
tree(int ml, int mh){make_tree(ml,mh);}
tree(tree const &src){size = src.size; p = src.p;}
};
void tree::make_tree(int ml, int mh){
int i,j,nl,nh,length,space;
nl=ml;
nh=mh;
size = (mh-ml+1);
space = size*(size+1)/2;
p = new node*[size];
p=p-ml;
p[ml] = new node[space];
//Code here which allocates the array of nodes to each of the pointers.
}
int nfields(char *line)
{
/* Counts the number of non-space entries in the line */
char *token;
int i=0;
token = strtok(line," "); //Read until space is encountered
while (token != NULL)
{
i++;
token = strtok(NULL," ");
}
return i;
}
mymatrix read(char *filename)
{
// Reads a file of doubles into a matrix which it passes on to the main routine
// Doubles are separated by a single space
//code that works fine by itself
}