嗨,我想知道哪一部分是错的?在我将头文件分成 .h 和 .cpp 后,编译器不起作用,我曾经将它们全部放在我的 .h 文件中,因为它们只是构造函数。谢谢!
图节点.h:
#ifndef Graphnode_H
#define Graphnode_H
#include <tr1/array>
//using namespace std;
class Graphnode {
public:
std::tr1::array<char, 16> state;
char x;
char depth;
char direction;
Graphnode(std::tr1::array<char, 16> _state,char _x,char _d,char _direction);
Graphnode();
};
#endif
图节点.cpp:
#include "Graphnode.h"
Graphnode::Graphnode()
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = 0;
}
x = 0;
depth = 0;
direction = 0;
}
Graphnode::Graphnode(std::tr1::array<char, 16> _state,char _x,char _d,char _direction)
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = _state[i];
}
x = _x;
depth = _d;
direction = _direction;
}
错误:
ZION:ods_v3 weeo$ make local
mpic++ -o local ods_v3.cpp -L/opt/local/lib/ -lboost_iostreams-mt -lz -I/opt/local/include
Undefined symbols for architecture x86_64:
"Graphnode::Graphnode(std::tr1::array<char, 16ul>, char, char, char)", referenced from:
_main in ods_v3-semJJ5.o
"Graphnode::Graphnode()", referenced from:
bfs(Graphnode, std::tr1::array<char, 16ul>, char, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >&) in ods_v3-semJJ5.o
dfs(Graphnode, std::tr1::array<char, 16ul>, char, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >, std::tr1::array<std::tr1::unordered_map<std::string, char, std::tr1::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, char> >, false>, 2000ul>) in ods_v3-semJJ5.o
readcheckfile(char const*, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >&) in ods_v3-semJJ5.o
_main in ods_v3-semJJ5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [local] Error 1