class OGraph {
public:
OGraph() { }
virtual ~OGraph();
virtual bool is_directed()=0;
};
class OUGraph : public OGraph {
public:
OUGraph() { }
bool is_directed() { return false; }
~OUGraph() {}
};
但是當我做這個問題繼承
OUGraph myGraph();
cout << myGraph.is_directed();
我收到以下錯誤:
Undefined symbols: "typeinfo for OGraph", referenced from: typeinfo for OUGraphin main.o "vtable for OGraph", referenced from: OGraph::OGraph()in main.o mkdir -p dist/Debug/GNU-MacOSX "OGraph::~OGraph()", referenced from: g++ -o dist/Debug/GNU-MacOSX/opengraph build/Debug/GNU-MacOSX/OGraph.o build/Debug/GNU-MacOSX/main.o
OUGraph::~OUGraph()in main.o OUGraph::~OUGraph()in main.o ld: symbol(s) not found collect2: ld returned 1 exit status make[2]: * [dist/Debug/GNU-MacOSX/opengraph] Error 1 make[1]: [.build-conf] Error 2 make: ** [.build-impl] Error 2BUILD FAILED (exit value 2, total time: 568ms)
對不起,我粘貼了錯誤的代碼。我剛剛更新了它,並收到了錯誤消息。 – Bob 2011-01-09 03:08:40