朋友类可以从C中的朋友类创建对象吗?
发布时间:2020-12-16 07:23:39 所属栏目:百科 来源:网络整理
导读:这些是我的两个C头文件中的代码,我在其中声明了两个类,一个是另一个的朋友: ==第一个类创建一个哈希表,并用给定文件中的单词填充它. #include "remove_duplicates.h"class Hash_class{protected: liststring *hashTable; string input_file; string output_
这些是我的两个C头文件中的代码,我在其中声明了两个类,一个是另一个的朋友:
==>第一个类创建一个哈希表,并用给定文件中的单词填充它. #include "remove_duplicates.h" class Hash_class{ protected: list<string> *hashTable; string input_file; string output_file; int input_file_size; friend class remove_duplicates; //void file_size(); public: /*load the words in the hash Table; by calculating the hash Code of each string*/ Hash_class(string input_file,string output_file="output_file.txt"); ~Hash_class(){ fclose(input_file); fclose(ouput_file); } int hashCode( const string input_word); void loadInHash(); void write_in_output(); int get_input_file_size(){ return input_file_size; } string get_input_file(){ return input_file; } string get_output_file(){ return output_file; } }; 在第二个类中,我想从第一个类创建一个对象并对其进行操作,首先填充创建的对象内的哈希表,然后删除所有重复的单词(如果Levenshtein距离接近某个比例) . #include "Hash_class.h" class remove_duplicates{ protected: Hash_class hash_object; public: remove_duplicates(Hash_class & hash_object); int Levenshtein_distance(string s1,string s2); void set_purge(); }; 问题是当我编译代码时出现错误:([错误]’Hash_class’没有命名类型) (“我使用C 4.3.2”) 解决方法
这看起来像一个循环包含.
>“Hash_class.h”包含“remove_duplicates.h” 要解决此问题,请从“Hash_class.h”中删除此行: #include "remove_duplicates.h" 这应该工作因为线 friend class remove_duplicates; 不需要有关如何实现类remove_duplicates的信息. 编辑:为避免进一步的错误,将两个头文件包装在include guards中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 深入理解Vue父子组件生命周期执行顺序及钩子函数
- xml – 向XSD架构添加版本的位置?
- ruby – 为什么我的IRB提示使用ANSI颜色代码会破坏页面向上
- oracle恢复误删除数据,解除锁定等非常经典实用方法
- Sqlite修改数据库表名修改、增加字段
- ruby – 在Sinatra应用程序中的gzip资产
- oracle11g ORA-12154: TNS:could not resolve the connect
- C#YamlDotNet库是否支持合并密钥?
- c# – 将Delegate对象传递给带有Func <>参数的方法
- reactjs – React.createElement:type无效 – 期望一个字符