【发布时间】:2013-05-18 18:01:01
【问题描述】:
这是 Graph.h 的内容,没有标题保护和其他功能
template <class T> class Node{
public:
T data;
Node<T> *NextNode;
public:
Node();
Node(T a);
T getValue();
void setValue(T a);
void chainNode(Node<T> a);
void chainNode(Node<T> *a);
Node<T> getNextNode();
void unchainNode();
};
//related methods
template <class T> Node<T>::Node(){
data = NULL;
NextNode = NULL;
}
template <class T> void Node<T>::chainNode(Node<T> a){
NextNode = NULL;
NextNode = &a;
}
template <class T> void Node<T>::chainNode(Node<T> *a){
NextNode = NULL;
NextNode = a;
}
template <class T> class List{
public:
Node<T> *Head;
List(Node<T> a);
void AddInFront(Node<T> a);
void AddInFront(Node<T> *a);
void Append(Node<T> a);
bool Remove(Node<T> a);
bool Remove(T a);
bool Contains(T a);
bool DeleteList();
};
//Only working method of List
template <class T> List<T>::List(Node<T> a){
Head = &a;
}
// Error occurs in this Function
template <class T> List<T>::AddInFront(Node<T> a){
a.chainNode(Head);
Head = NULL;
Head = &a;
}
这是我的主线
#include<iostream>
#include"Graph.h"
int main(){
Node<int> a = Node<int>(20);
List<int> d = List<int>(a);
Node<int> b = Node<int>(20);
d.AddInFront(b);
}
这是我的错误
error C4430: Missing type specifier - int assumed . Note: C++ does not support default- int
我的编译器 (MSVS 11) 告诉我,我在 AddInFront 函数的末尾有一个 C4430 错误,最后我的意思是说除了结尾大括号之外的任何内容都有错误。我已经尝试了下面的所有内容月亮试图摆脱这个错误,但我似乎无法修复它。
【问题讨论】:
-
顺便说一句,
Node<int> a(20);
标签: c++ templates visual-c++ data-structures compiler-errors