| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1945 人关注过本帖
标题:类声明老报错
只看楼主 加入收藏
lebronze
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2016-5-25
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:2 
类声明老报错
头文件里声明的类,代码如下:
程序代码:
#ifndef HNODE_H
#define HNODE_H
class Hnode  //哈夫曼树的存储存储结构
{
public:
    unsigned char name;    //8位的存储单元来存储字符(256种)
    unsigned  weight;  //存储字符的频度
    int p; //双亲节点
    int lchild; //左孩子
    int rchild; //右孩子
    int Hnodeindex;  //节点索引
    Hnode() //初始化数据成员
    {
        name = '\0';
        weight = 0;
        p = 0;
        Hnodeindex = 0;
        lchild = rchild = 0;
    }
};
#endif

一直在报错:
1>e:\test2\test2\comandex.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>e:\test2\test2\hnode.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>e:\test2\test2\hnode.h(4): error C2059: 语法错误:“public”
1>e:\test2\test2\hnode.h(4): error C2143: 语法错误 : 缺少“;”(在“:”的前面)
1>e:\test2\test2\hnode.h(4): error C2059: 语法错误:“:”
1>e:\test2\test2\hnode.h(8): error C2059: 语法错误:“)”
1>e:\test2\test2\hnode.h(10): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(10): error C2371: “weight”: 重定义;不同的基类型
1>          e:\test2\test2\hnode.h(6) : 参见“weight”的声明
1>e:\test2\test2\hnode.h(11): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(12): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(13): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(13): error C2086: “int lchild”: 重定义
1>          e:\test2\test2\hnode.h(7) : 参见“lchild”的声明
1>e:\test2\test2\hnode.h(13): error C2065: “rchild”: 未声明的标识符
1>e:\test2\test2\hnode.h(14): error C2059: 语法错误:“}”
1>e:\test2\test2\hnode.h(14): error C2143: 语法错误 : 缺少“;”(在“}”的前面)
1>e:\test2\test2\hnode.h(14): error C2059: 语法错误:“}”
1>e:\test2\test2\hnode.h(15): error C2143: 语法错误 : 缺少“;”(在“}”的前面)
1>e:\test2\test2\hnode.h(15): error C2059: 语法错误:“}”
很奇怪
搜索更多相关主题的帖子: 声明 int C2059 语法错误 缺少 
2017-06-20 22:47
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9008
专家分:53957
注 册:2011-1-18
收藏
得分:10 
你贴的是 e:\test2\test2\hnode.h 吗?

e:\test2\test2\hnode.h(10): error C2371: “weight”: 重定义;不同的基类型
------ 第10行没有weight
2017-06-21 08:20
lebronze
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2016-5-25
收藏
得分:0 
回复 2楼 rjsp
代码提额的没问题,我感觉出错可能是在配置方面,下面是全部的编译信息:

1>ClCompile:
1>  main.cpp
1>e:\test2\test2\comandex.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>e:\test2\test2\hnode.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>e:\test2\test2\hnode.h(4): error C2059: 语法错误:“public”
1>e:\test2\test2\hnode.h(4): error C2143: 语法错误 : 缺少“;”(在“:”的前面)
1>e:\test2\test2\hnode.h(4): error C2059: 语法错误:“:”
1>e:\test2\test2\hnode.h(8): error C2059: 语法错误:“)”
1>e:\test2\test2\hnode.h(10): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(10): error C2371: “weight”: 重定义;不同的基类型
1>          e:\test2\test2\hnode.h(6) : 参见“weight”的声明
1>e:\test2\test2\hnode.h(11): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(12): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(13): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test2\test2\hnode.h(13): error C2086: “int lchild”: 重定义
1>          e:\test2\test2\hnode.h(7) : 参见“lchild”的声明
1>e:\test2\test2\hnode.h(13): error C2065: “rchild”: 未声明的标识符
1>e:\test2\test2\hnode.h(14): error C2059: 语法错误:“}”
1>e:\test2\test2\hnode.h(14): error C2143: 语法错误 : 缺少“;”(在“}”的前面)
1>e:\test2\test2\hnode.h(14): error C2059: 语法错误:“}”
1>e:\test2\test2\hnode.h(15): error C2143: 语法错误 : 缺少“;”(在“}”的前面)
1>e:\test2\test2\hnode.h(15): error C2059: 语法错误:“}”
2017-06-21 09:24
快速回复:类声明老报错
数据加载中...
 
   



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

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