C++ 链接错误:未定义引用-友元函数

C++ 链接错误:未定义引用-友元函数,c++,undefined-reference,friend-function,C++,Undefined Reference,Friend Function,只是突出的细节: 汇编: g++ -c memref_test.cpp g++ -c -I/home/chap/private/WDI/git -I/home/chap/private/WDI/git/include -I/usr/local/mysql/include -I/usr/local/include -I/home/chap/private/WDI/git -I/home/chap/private/WDI/git/include -I/usr/include/mysql -fno

只是突出的细节:

汇编

g++ -c memref_test.cpp
g++ -c -I/home/chap/private/WDI/git -I/home/chap/private/WDI/git/include -I/usr/local/mysql/include -I/usr/local/include   -I/home/chap/private/WDI/git -I/home/chap/private/WDI/git/include -I/usr/include/mysql -fno-strict-aliasing  -g -O0 --std=c++11  MemRef.cpp
g++ -o memref_test memref_test.o MemRef.o
MemRef.h:36:24: warning: inline function ‘bool operator<(const MemRef&, const MemRef&)’ used but never defined [enabled by default]

/usr/include/c++/4.7/bits/stl_algo.h:86: undefined reference to `operator<(MemRef const&, MemRef const&)'
class MemRef {
    public:
        friend inline bool operator< (const MemRef& lhs, const MemRef& rhs);
};
inline bool 
operator< (const MemRef& lhs, const MemRef& rhs){
    int minlen = 
        lhs._len <= rhs._len 
        ? lhs._len 
        : rhs._len;
    int res = memcmp(lhs._ptr, rhs._ptr, minlen);
    if (res < 0) return true;
    if (res > 0) return false;
    // equal for minlen, so he with the lesser length wins
    return (lhs._len < rhs._len);
}
deque<MemRef> memrefs;
const string record("Record 1\tABLE\tBAKER\tCHARLIE");
MemRef::split(memrefs, record, '\t');
std::sort(memrefs.begin(), memrefs.end());
错误

g++ -c memref_test.cpp
g++ -c -I/home/chap/private/WDI/git -I/home/chap/private/WDI/git/include -I/usr/local/mysql/include -I/usr/local/include   -I/home/chap/private/WDI/git -I/home/chap/private/WDI/git/include -I/usr/include/mysql -fno-strict-aliasing  -g -O0 --std=c++11  MemRef.cpp
g++ -o memref_test memref_test.o MemRef.o
MemRef.h:36:24: warning: inline function ‘bool operator<(const MemRef&, const MemRef&)’ used but never defined [enabled by default]

/usr/include/c++/4.7/bits/stl_algo.h:86: undefined reference to `operator<(MemRef const&, MemRef const&)'
class MemRef {
    public:
        friend inline bool operator< (const MemRef& lhs, const MemRef& rhs);
};
inline bool 
operator< (const MemRef& lhs, const MemRef& rhs){
    int minlen = 
        lhs._len <= rhs._len 
        ? lhs._len 
        : rhs._len;
    int res = memcmp(lhs._ptr, rhs._ptr, minlen);
    if (res < 0) return true;
    if (res > 0) return false;
    // equal for minlen, so he with the lesser length wins
    return (lhs._len < rhs._len);
}
deque<MemRef> memrefs;
const string record("Record 1\tABLE\tBAKER\tCHARLIE");
MemRef::split(memrefs, record, '\t');
std::sort(memrefs.begin(), memrefs.end());

MemRef.h:36:24:警告:内联函数'bool运算符或从运算符和友元decl中删除
inline
,或将整个内容移动到头文件。我搜索了一下'inline',决定只删除关键字。工作。