B
blueblueblue2005
Hi, here is an example I copied from Deitel C++ book. but when I
compile it, always get the above compilation error, no matter how I
change the include order, please help.
here is the files:
Note: this is to practice Proxy classes.
// Implementation.h
class Implementation {
public:
Implementation(int v) { this->v = v; }
void setValue(int v)
{
this->v = v;
}
int getValue() const
{
return v;
}
private:
int v;
};
// Interface.h
class Implementation;
class Interface {
public:
Interface(int);
~Interface();
void setValue(int);
int getValue() const;
private:
Implementation *ptr;
};
/* Interface.cpp */
#include "Implementation.h"
#include "Interface.h"
Interface::Interface(int v)
tr(new Implementation(v))
{ }
Interface::~Interface() { delete ptr; }
void Interface::setValue(int v){
ptr->setValue(v);
}
int Interface::getValue() const {
return ptr->getValue();
}
/* t.cpp */
#include <iostream>
using namespace std;
#include "Interface.h"
#include "Implementation.h"
int main(){
Interface i(5);
cout << i.getValue() << endl;
i.setValue(19);
cout << i.getValue() << endl;
return 0;
}
# ============ this is Makefile
# Makefile
a.out: Implementation.h Interface.h Interface.cpp t.cpp
g++ Implementation.h Interface.cpp t.cpp
clean:
rm -f a.out
cleanall:
rm -f *.h *.cpp a.out
compile it, always get the above compilation error, no matter how I
change the include order, please help.
here is the files:
Note: this is to practice Proxy classes.
// Implementation.h
class Implementation {
public:
Implementation(int v) { this->v = v; }
void setValue(int v)
{
this->v = v;
}
int getValue() const
{
return v;
}
private:
int v;
};
// Interface.h
class Implementation;
class Interface {
public:
Interface(int);
~Interface();
void setValue(int);
int getValue() const;
private:
Implementation *ptr;
};
/* Interface.cpp */
#include "Implementation.h"
#include "Interface.h"
Interface::Interface(int v)
{ }
Interface::~Interface() { delete ptr; }
void Interface::setValue(int v){
ptr->setValue(v);
}
int Interface::getValue() const {
return ptr->getValue();
}
/* t.cpp */
#include <iostream>
using namespace std;
#include "Interface.h"
#include "Implementation.h"
int main(){
Interface i(5);
cout << i.getValue() << endl;
i.setValue(19);
cout << i.getValue() << endl;
return 0;
}
# ============ this is Makefile
# Makefile
a.out: Implementation.h Interface.h Interface.cpp t.cpp
g++ Implementation.h Interface.cpp t.cpp
clean:
rm -f a.out
cleanall:
rm -f *.h *.cpp a.out