LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2388|回复: 5

用g++ 编程的问题(头文件)

[复制链接]
发表于 2006-9-27 15:03:07 | 显示全部楼层 |阅读模式
用c++编写了一个程序(在附件中,其中的EnhancedLinkedList.h自己编写,另两个一个是测试用,一个是已经提供的程序),然后用g++编译: g++ testdriver.cpp -o testdriver

出现错误如下:

spirit@freefly:~/EX/OE1/handout-files$ g++ testdriver.cpp -o testdriver
EnhancedLinkedList.h: In member function ‘T& EnhancedLinkedList<T>::find_first(const T&)’:
EnhancedLinkedList.h:13: 错误: ‘head’ 在此作用域中尚未声明
EnhancedLinkedList.h: In member function ‘EnhancedLinkedList<T> EnhancedLinkedList<T>::find_all(const T&)’:
EnhancedLinkedList.h:27: 错误: ‘head’ 在此作用域中尚未声明
EnhancedLinkedList.h: In member function ‘void EnhancedLinkedList<T>::remove_first(const T&)’:
EnhancedLinkedList.h:42: 错误: ‘head’ 在此作用域中尚未声明
EnhancedLinkedList.h:52: 错误: there are no arguments to ‘pop_front’ that depend on a template parameter, so a declaration of ‘pop_front’ must be available
EnhancedLinkedList.h:52: 错误: (如果您使用 ‘-fpermissive’,G++ 会接受您的代码,但是允许使用未定义的名称是过时的风格)
EnhancedLinkedList.h:53: 错误: no post-decrement operator for type
EnhancedLinkedList.h:60: 错误: no post-decrement operator for type
EnhancedLinkedList.h:63: 错误: ‘tail’ 在此作用域中尚未声明
EnhancedLinkedList.h:64: 错误: there are no arguments to ‘pop_back’ that depend on a template parameter, so a declaration of ‘pop_back’ must be available
EnhancedLinkedList.h:65: 错误: no post-decrement operator for type
EnhancedLinkedList.h: In member function ‘T& EnhancedLinkedList<T>::find_first(const T&) [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
testdriver.cpp:25:   instantiated from here
EnhancedLinkedList.h:17: 错误: 不能将 ‘search-> Node<T>::getData [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]()’ 转换为 ‘bool’
EnhancedLinkedList.h: In member function ‘EnhancedLinkedList<T> EnhancedLinkedList<T>::find_all(const T&) [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
testdriver.cpp:110:   instantiated from here
EnhancedLinkedList.h:33: 错误: 不能将 ‘search-> Node<T>::getData [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]()’ 转换为 ‘bool’
EnhancedLinkedList.h: In member function ‘void EnhancedLinkedList<T>::remove_first(const T&) [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
testdriver.cpp:122:   instantiated from here
EnhancedLinkedList.h:47: 错误: 不能将 ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’ 转换为 ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >*’,在 assignment 中
EnhancedLinkedList.h:48: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
EnhancedLinkedList.h:49: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
EnhancedLinkedList.h:50: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
testdriver.cpp:122:   instantiated from here
EnhancedLinkedList.h:56: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
EnhancedLinkedList.h:57: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
EnhancedLinkedList.h:58: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
EnhancedLinkedList.h:59: 错误: type ‘class Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’ argument given to ‘delete’, expected pointer
testdriver.cpp:122:   instantiated from here
EnhancedLinkedList.h:70: 错误: base operand of ‘->’ has non-pointer type ‘Node<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’


希望大家查看一下附件,我认为是EnhancedLinkedList.h头文件没有将LinkedList.h头文件包含进去的原因,其中涉及了头文件的互相包括,希望大家帮忙看看,谢谢!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2006-9-27 16:57:08 | 显示全部楼层
g++ -I./ testdriver.cpp -o testdriver
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-27 18:28:46 | 显示全部楼层
î˜Ø是¡有ã³...期待中... ^_^
回复 支持 反对

使用道具 举报

发表于 2006-9-27 19:10:41 | 显示全部楼层
本应这样能解决的:

g++ -I. -I./handout-files testdriver.cpp

但是楼主的程序问题太多。从模板类继承下来的派生类在引用基类成员时应该加上`this->',因为基类成员不在查找域中(Koenig Lookup)。而且很多不返回整型的量也用来判断。很多是程序本身的问题。楼主好好修改下吧。
回复 支持 反对

使用道具 举报

发表于 2006-9-28 17:40:08 | 显示全部楼层
问题解决了吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-28 19:53:23 | 显示全部楼层
刚才在ž验¤上的debianûß
(gcc version 3.3.5 (Debian 1:3.3.5-13))
上Û行了ô改,Ѱ编Ñ通Ç了,Þ»Ø会在我êñ的kubuntu上再次ô改编Ñ来验Á
谢谢Þ贴的两位大å!^_^
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表