| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2633 人关注过本帖
标题:LNK2019: 无法解析的外部符号
只看楼主 加入收藏
tanhe00
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-21
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
LNK2019: 无法解析的外部符号
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <map>
#pragma comment(lib,"ws2_32.lib")

using  namespace std;

class TextQuery
{
public:
    typedef std::vector<std::string>::size_type line_no;
    void read_file( std::ifstream &is )
    {
        store_file(is);
        build_map();
    }
    std::set<line_no> run_query(const std::string & ) const;
    std::string text_line(line_no) const;
private:
    void store_file(std::ifstream&);
    void build_map();
    std::vector<std::string>lines_of_text;
    std::map< std::string, std::set<line_no> > word_map;
};

string make_plural(size_t ctr, const string &word, const string &ending);
void print_results(const set<TextQuery::line_no>& locs,const string& sought,const TextQuery &file);
ifstream& open_file(ifstream &in,const string &file);

string make_plural(size_t ctr, const string &word, const string &ending)
{
    return(ctr == 1)? word:word+ending;
}

void print_results(const set<TextQuery::line_no>& locs,const string& sought,const TextQuery &file)
{
    typedef set<TextQuery::line_no>line_nums;
    line_nums::size_type size=locs.size();
    cout << "\n" << sought << "occours" <<size << " " <<make_plural(size,"time", "s") << endl;
    line_nums::const_iterator it = locs.begin();
    for(;it != locs.end();++it)
    {
        cout << "\t(line" << (*it)+1 << ")" << file.text_line(*it) <<endl;
    }

}

ifstream& open_file(ifstream &in,const string &file)
{
    in.close();
    in.clear();
    in.open(file.c_str());
    return in;
}

int main(int argc,char **argv)
{
    ifstream infile;
    if(argc < 2|| !open_file(infile,argv[1]))
    {
        cerr << "No input file!" << endl;
        return EXIT_FAILURE;
    }
    TextQuery tq;
    tq.read_file(infile);
    while(true){
        cout << "enter word to look for, or q to quit :";
        string s;
        cin >>s;
        if (!cin || s=="q")break;
        set<TextQuery::line_no>locs = tq.run_query(s);
        print_results(locs,s,tq);
    }
    return 0;
}



1>------ 已启动生成: 项目: TextQuery, 配置: Debug Win32 ------
1>生成启动时间为 2011/6/21 19:08:02。
1>InitializeBuildStatus:
1>  正在对“Debug\TextQuery.unsuccessfulbuild”执行 Touch 任务。
1>ClCompile:
1>  main.cpp
1>ManifestResourceCompile:
1>  所有输出均为最新。
1>main.obj : error LNK2019: 无法解析的外部符号 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall TextQuery::text_line(unsigned int)const " (?text_line@TextQuery@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@I@Z),该符号在函数 "void __cdecl print_results(class std::set<unsigned int,struct std::less<unsigned int>,class std::allocator<unsigned int> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class TextQuery const &)" (?print_results@@YAXABV?$set@IU?$less@I@std@@V?$allocator@I@2@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@ABVTextQuery@@@Z) 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: class std::set<unsigned int,struct std::less<unsigned int>,class std::allocator<unsigned int> > __thiscall TextQuery::run_query(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?run_query@TextQuery@@QBE?AV?$set@IU?$less@I@std@@V?$allocator@I@2@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "private: void __thiscall TextQuery::build_map(void)" (?build_map@TextQuery@@AAEXXZ),该符号在函数 "public: void __thiscall TextQuery::read_file(class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?read_file@TextQuery@@QAEXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@@Z) 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "private: void __thiscall TextQuery::store_file(class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?store_file@TextQuery@@AAEXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@@Z),该符号在函数 "public: void __thiscall TextQuery::read_file(class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?read_file@TextQuery@@QAEXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@@Z) 中被引用
1>c:\users\kkk\documents\visual studio 2010\Projects\TextQuery\Debug\TextQuery.exe : fatal error LNK1120: 4 个无法解析的外部命令
1>
1>生成失败。
1>
1>已用时间 00:00:01.28
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========



完全不明白啊。。。。。确实是直接用的c++ primer上的代码为什么会出现这种错误呢?
搜索更多相关主题的帖子: 符号 
2011-06-21 19:17
玩出来的代码
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:河南新乡
等 级:贵宾
威 望:11
帖 子:742
专家分:2989
注 册:2009-10-12
收藏
得分:7 

离恨恰如春草,更行更远还生。
2011-06-21 23:51
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:7 
错误提示已经说得很清楚啦
text_line
run_query
build_map
store_file
这四个成员函数没实现
2011-06-22 10:56
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:7 
楼主要学会看错误提示。
2011-06-22 17:31
快速回复:LNK2019: 无法解析的外部符号
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017849 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved