目前我在书中学习C++,他们有一个关于使用以前创建的名为IntList的类并使用IntListProxy实现它的练习。我的书只是以一个非常简单的例子来谈论代理服务器,所以我很难理解它的语法。我在做什么这个代理错了,我该如何解决它?请记住,IntList已经是.o,我不允许在编译时包含IntList.cpp。 错误:语法错误与代理:我做错了什么?
IntListProxy.cpp: In member function ‘bool IntListProxy::isEmpty()’:
IntListProxy.cpp:7: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘IntListProxy* IntListProxy::prepend(int)’:
IntListProxy.cpp:13: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘int IntListProxy::head()’:
IntListProxy.cpp:19: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘IntListProxy* IntListProxy::tail()’:
IntListProxy.cpp:25: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘std::string IntListProxy::toString()’:
IntListProxy.cpp:31: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘int IntListProxy::length()’:
IntListProxy.cpp:37: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘IntListProxy* `IntListProxy::append(IntListProxy*)’:`
IntListProxy.cpp:43: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp: In member function ‘int IntListProxy::operator[](int)’:
IntListProxy.cpp:49: error: invalid use of incomplete type ‘struct IntList’
IntListProxy.h:5: error: forward declaration of ‘struct IntList’
IntListProxy.cpp:51: error: expected unqualified-id before ‘}’ token
IntListProxy.cpp:51: error: expected ‘;’ before ‘}’ token
IntListProxy.h
#include <iostream>
#include <string>
using namespace std;
class IntList;
class IntListProxy
{
public:
IntListProxy();
bool isEmpty();
IntListProxy *prepend(int n);
int head();
IntListProxy *tail();
string toString();
int length();
IntListProxy *append(IntListProxy *lst);
int operator[](int n);
private:
IntList *ptr;
};
IntListProxy.cpp
#include "IntListProxy.h"
IntListProxy::IntListProxy(){}
bool IntListProxy::isEmpty(){
ptr->isEmpty();
}
IntListProxy *IntListProxy::prepend(int n){
return ptr->prepend(n);
}
int IntListProxy::head(){
return ptr->head();
}
IntListProxy *IntListProxy::tail(){
return ptr->tail();
}
string IntListProxy::toString(){
return ptr->toString();
}
int IntListProxy::length(){
return ptr->length();
}
IntListProxy *IntListProxy::append(IntListProxy *lst){
return ptr->append(lst);
}
int IntListProxy::operator[](int n){
return ptr->operator[](n);
}
预先感谢您!