S
suresh.amritapuri
Hi,
This is my code:
//tree.h file
#ifndef TREE_H_
#define TREE_H_
#include "factorGraph.h"
template <typename Vertex>
class Tree{
public:
Tree(FactorGraph f):fg(f){}
Vertex root(){return root;} //returns the root
void root(Vertex rt){rootVertex=rt;} //sets the root
friend ostream & operator<<(ostream& o, const Tree<Vertex>& );
void test();
private:
Vertex rootVertex;
FactorGraph fg;
};
#endif /* TREE_H_ */
//tree.cpp file
#include "tree.h"
template<typename Vertex>
ostream & operator<< <>(ostream& o, const Tree<Vertex>& t ){
o << t.fg << endl;
return o;
}
template<typename Vertex>
void Tree<Vertex>::test(){ cout << "Namasivayah" << endl;}
I compile like this:
g++ -c tree.cpp -o tree.o
and link with other object files in my project.
I get the following linker errors:
undefined reference to `Tree<vertex_properties>::test()'
undefined reference to `operator<<(std::basic_ostream<char,
std::char_traits<char> >&, Tree<vertex_properties> const&)'
collect2: ld returned 1 exit status
I tried including the tree.cpp file at the end of tree.h. But even
then operator<< function is not compiling.
How do I go further?
suresh
This is my code:
//tree.h file
#ifndef TREE_H_
#define TREE_H_
#include "factorGraph.h"
template <typename Vertex>
class Tree{
public:
Tree(FactorGraph f):fg(f){}
Vertex root(){return root;} //returns the root
void root(Vertex rt){rootVertex=rt;} //sets the root
friend ostream & operator<<(ostream& o, const Tree<Vertex>& );
void test();
private:
Vertex rootVertex;
FactorGraph fg;
};
#endif /* TREE_H_ */
//tree.cpp file
#include "tree.h"
template<typename Vertex>
ostream & operator<< <>(ostream& o, const Tree<Vertex>& t ){
o << t.fg << endl;
return o;
}
template<typename Vertex>
void Tree<Vertex>::test(){ cout << "Namasivayah" << endl;}
I compile like this:
g++ -c tree.cpp -o tree.o
and link with other object files in my project.
I get the following linker errors:
undefined reference to `Tree<vertex_properties>::test()'
undefined reference to `operator<<(std::basic_ostream<char,
std::char_traits<char> >&, Tree<vertex_properties> const&)'
collect2: ld returned 1 exit status
I tried including the tree.cpp file at the end of tree.h. But even
then operator<< function is not compiling.
How do I go further?
suresh