Actuellement j'apprends le C++ dans mon livre et ils ont eu un exercice sur l'utilisation d'une classe précédemment créée appelée IntList et l'implémentent en utilisant IntListProxy. Mon livre ne parle que des procurations dans un exemple très simple, donc j'ai du mal avec la syntaxe. Qu'est-ce que je fais de mal avec ce proxy et comment puis-je le réparer? Gardez à l'esprit IntList est déjà un .o et je ne suis pas autorisé à inclure IntList.cpp lorsque je compile ceci. L'erreur:Erreurs de syntaxe avec les proxies: Que fais-je de mal?
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);
}
Merci d'avance!