目前我在書中學習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);
}
預先感謝您!