首页 > 编程语言 > 详细

C++ primer中,"单词转换"map对象源码问题

时间:2014-02-20 11:53:36      阅读:455      评论:0      收藏:0      [点我收藏+]

单独编译word_transform.cc文件的时候报错:

word_transform.cc:(.text+0x133):对‘open_file(std::basic_ifstream<char, std::char_traits<char> >&, std::string const&)’未定义的引用
word_transform.cc:(.text+0x533):对‘open_file(std::basic_ifstream<char, std::char_traits<char> >&, std::string const&)’未定义的引用
word_transform.cc:(.text+0x703):对‘open_file(std::basic_ifstream<char, std::char_traits<char> >&, std::string const&)’未定义的引用
collect2: 错误: ld 返回 1

原因:word_transform.cc这个文件的源码中,只在最上面声明了open_file()函数。但是没有在后面实现该函数,所以,会报open_file()未定义的错误。

ifstream& open_file(ifstream&, const string&); 

其源码如下: 
ifstream& open_file(ifstream &in, const string &file) 
{ 
in.close(); // close in case it was already open 
in.clear(); // clear any existing errors 
// if the open fails, the stream will be in an invalid state 
in.open(file.c_str()); // open the file we were given 
return in; // condition state is good if open succeeded 
} 
在word_transform.cc文件最下面加上open_file()函数源码就可以正常运行了。

注:通过makefile文件将gnu_files文件夹下所有源码一起编译word_transform.cc是可以通过的,所以,说明open_file这个函数是在某个文件里面实现了。只是本来找人半天没找到在哪里。如果有人找到可以tell me,tksbubuko.com,布布扣

C++ primer中,"单词转换"map对象源码问题

原文:http://blog.csdn.net/zhouhong1026/article/details/19493833

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!