qq_34395778 2016-11-22 16:00 采纳率: 0%
浏览 2451

明明无错却出现:不可识别的模板声明/定义

源码:(vs2015)
#include

using namespace std;

//节点类(抽象类)
template
class HuffNode
{
public:
HuffNode(){}
virtual ~HuffNode() {}

virtual int weight() = 0;

virtual bool isLeaf() = 0;

};

//叶节点类(继承自节点类)
template
class LeafNode :pulic HuffNode
{
private:
E it;

int wgt;

public:

//构造叶节点
LeafNode(const E& val, int freq)
{
    it = val;
    wgt = freq;
}

//返回该叶节点的权值
int weight() 
{ 
    return wgt; 
}

//返回节点的值
E val() 
{
    return it; 
}

//判断是否是叶节点
bool isLeaf() 
{
    return true; 
}

};

错误报告:
1>------ 已启动生成: 项目: Huffman编码, 配置: Debug Win32 ------
1> main.cpp
1>c:\users\asus\desktop\huffman编码\huffman编码\huffman.h(14): error C2988: 不可识别的模板声明/定义
1>c:\users\asus\desktop\huffman编码\huffman编码\huffman.h(14): error C2143: 语法错误: 缺少“;”(在“<”的前面)
1>c:\users\asus\desktop\huffman编码\huffman编码\huffman.h(14): error C2059: 语法错误:“<”
1>c:\users\asus\desktop\huffman编码\huffman编码\huffman.h(15): error C2143: 语法错误: 缺少“;”(在“{”的前面)
1>c:\users\asus\desktop\huffman编码\huffman编码\huffman.h(15): error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>c:\users\asus\desktop\huffman编码\huffman编码\huffman.h(25): error C2143: 语法错误: 缺少“,”(在“”的前面)

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-11-22 16:11
    关注

    模板没写对,public拼写错了,修改如下

     #include <iostream>
    
    using namespace std;
    
    //节点类(抽象类)
    template <typename E>
    class HuffNode 
    {
    public:
        HuffNode(){}
        virtual ~HuffNode() {}  
        virtual int weight() = 0;   
        virtual bool isLeaf() = 0;   
    };
    
    //叶节点类(继承自节点类)
    template<typename E>
    class LeafNode :public HuffNode<E>
    {
    private:
        E it;   
        int wgt;    
    public:
    
        //构造叶节点
        LeafNode(const E& val, int freq)
        {
            it = val;
            wgt = freq;
        }
    
        //返回该叶节点的权值
        int weight() 
        { 
            return wgt; 
        }
    
        //返回节点的值
        E val() 
        {
            return it; 
        }
    
        //判断是否是叶节点
        bool isLeaf() 
        {
            return true; 
        }
    };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计