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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?