主题:c++中各种文件之间的包含与组织
Query_base是抽象基类,WordQuery,NotQuery和BinaryQuery继承Query_base类,BinaryQuery也是抽象类,AndQuery和OrQuery继承BinaryQuery类,Query是句柄指针类。Query类重载&,~,|,他们分别需要访问AndQuery,OrQuery,NotQuery,在Query中已经分别将要重载的函数设为友元,因为要返回派生类,所以在派生类定义后才能实现重载函数,
要实现的操作为比如:
Query operator&(const Query& first,const Query& second)
{ return new AndQuery(first,second);}//这里以用复制构造函数将类的指针 // 转化为Query对象
以下是我的文件组织形式
Query.h中用#include "Query_base.h"
Query_base.h 不用包含
WordQuery.h中
#include "Query_base.h"
#include "Query.h"
class WordQuery:public Query_base{....}
Query::Query(const string& s)
{ return new WordQuery(s);}
NotQuery.h中
#include "Query_base.h"
#include "Query.h"
class NotQuery::public Query_base{....}
Query operator~(const Query& query)
{ return new NotQuery(query);}
BinaryQuery.h中
#include "Query_base.h"
AndQuery.h中
#include "BinaryQuery.h"
#include "Query.h"
class AndQuery:public BinaryQuery{...}
Query operator&(const Query& first,const Query& second)
{ return new AndQuery(first,second);}
OrQuery.h中
#include "BinaryQuery.h"
#include "OrQuery.h"
class OrQuery:public BinaryQuery{....}
Query operator|(const Query& first,const Query& second)
{ return new OrQuery(first,second);}
然后编译链接时提示的错误为
[Linker error] undefined reference to `Query::Query(std::string const&)' [Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `operator&(Query const&, Query const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `operator&(Query const&, Query const&)'
[Linker error] undefined reference to `operator|(Query const&, Query const&)'
求高手帮我解释下原因,如何解决,详细点,谢谢
可以的话顺便给点编译链接的资料
要实现的操作为比如:
Query operator&(const Query& first,const Query& second)
{ return new AndQuery(first,second);}//这里以用复制构造函数将类的指针 // 转化为Query对象
以下是我的文件组织形式
Query.h中用#include "Query_base.h"
Query_base.h 不用包含
WordQuery.h中
#include "Query_base.h"
#include "Query.h"
class WordQuery:public Query_base{....}
Query::Query(const string& s)
{ return new WordQuery(s);}
NotQuery.h中
#include "Query_base.h"
#include "Query.h"
class NotQuery::public Query_base{....}
Query operator~(const Query& query)
{ return new NotQuery(query);}
BinaryQuery.h中
#include "Query_base.h"
AndQuery.h中
#include "BinaryQuery.h"
#include "Query.h"
class AndQuery:public BinaryQuery{...}
Query operator&(const Query& first,const Query& second)
{ return new AndQuery(first,second);}
OrQuery.h中
#include "BinaryQuery.h"
#include "OrQuery.h"
class OrQuery:public BinaryQuery{....}
Query operator|(const Query& first,const Query& second)
{ return new OrQuery(first,second);}
然后编译链接时提示的错误为
[Linker error] undefined reference to `Query::Query(std::string const&)' [Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `operator&(Query const&, Query const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `Query::Query(std::string const&)'
[Linker error] undefined reference to `operator&(Query const&, Query const&)'
[Linker error] undefined reference to `operator|(Query const&, Query const&)'
求高手帮我解释下原因,如何解决,详细点,谢谢
可以的话顺便给点编译链接的资料