开发者

The exercise 15.41 in book of c++ primer 4th [closed]

开发者 https://www.devze.com 2023-01-24 02:08 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago. 开发者_开发知识库
class Query{
    friend Query operator&(const Query&,const Query&);
    friend Query operator|(const Query&,const Query&);
    friend Query operator~(const Query&);
public:
    Query(const string&);           //build a new WordQuery ??
    Query(const Query&c):p(c.p),use(c.use){++*use;}
    ~Query(){delQuery();}
    Query operator=(const Query&c);
    set<TextQuery::line_no> eval(const TextQuery&c) const{return p->eval(c);}
    ostream& display(ostream&s) const {return p->display(s);}
private:
    Query(QueryBase *query):p(query),use(new size_t(1)){}
    QueryBase *p;
    size_t* use;
    void delQuery(){
        if(--*use==0)
            delete p;
            delete use;
    }
};

class WordQuery:public QueryBase{
    friend class Query;
    WordQuery(const string& s):QueryWord(s){}  //Query use the WordQuery constructor
    set<lineno> eval(const TextQuery&t) const
    {return t.run_query(QueryWord);}
    ostream& display(ostream& os) const
    {return os<<QueryWord;}
    string QueryWord;
};

I invoke it in expression Query q=Query(s1) & Query(s2) | Query(s3);

ERRORS:"TextQueryADVANCE.cpp:(.text+0x15ba): undefined reference to `Query::Query(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
"


It appears that you put the prototype for the constructor, but you didn't actually put an implementation.

You put: Query(const string&);, which says that there is a constructor somewhere that takes a string and creates a Query with it. However, somewhere you actually have to put something that does that.


This is a linker error. It seems you have not provided an implementation for Query(const string&).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号