gpt4 book ai didi

c++模板没有合适的默认构造函数

转载 作者:行者123 更新时间:2023-11-27 23:21:14 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why should the implementation and the declaration of a template class be in the same header file?

希望你能帮助我。

我知道这个问题(在进行谷歌搜索后)已被问过数百万次。我确信我的问题的解决方案就在数百万个问题中的一个,但我找不到,所以我决定问问。

我特别收到这个错误:

Error 1 error C2512: 'NodeQueue' : no appropriate default constructor available a:\work\fast\semi 5\automata\assignments\progass1\progass1\progass1\tree.h 33 1 progass1

具体行有这样的定义:

level=new NodeQueue<Node>;

下一行也出现同样的错误,但原因是一样的..

我有所有不确定为什么会发生这种情况的默认构造函数。以下是部分代码:

头文件的顶部:

#include <iostream>
using namespace std;

#include "intarr.h"
class Node;
template <typename t>
class QueueNode;

template <typename t>
class NodeQueue;

树:

class Tree{

Node* root;


int level_length;
Node* curr;
NodeQueue <Node>* level,*level_bak;
public:

Tree(){
root=NULL;
level_length=0;
curr=NULL;
level=new NodeQueue<Node>;
level_bak=new NodeQueue<Node>;
}
// I doubt you need the rest...

类节点

class Node{
public:
Node *top,*right,*bottom,*left,*prev;
Node *a,*b,*c;
int row,col;
Node(){

}
Node(int x,int y){
top=right=bottom=left=prev=NULL;
row=x;col=y;
a=b=c=NULL;
}

};

queuenode(即队列的节点)

 template <typename t>
class QueueNode {
public:
QueueNode* next;
QueueNode* prev;

t *value;
QueueNode(){

}
QueueNode(t* value){
next=NULL;
this->value=value;
}

};

节点队列:

 template <typename t>
class NodeQueue {
QueueNode *head;
QueueNode *tail;

//lhs=bottom;

public:
NodeQueue(){
head=NULL;
tail=NULL;
}
//....... rest of the code you dont need

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com