C
cody
Hello fols. I'm doin a school project and have this stupid problem. We're
on virtual functions and have to seperate out each class into a file. There
are 9 classes and so 9 .h and .c files. the file structure is something
like this.
control
|
formula
|| |
|| |
|| Operation
|variable |||
literal ||AND
|XOR
OR
So formula inherits from control and operation from formula and etc. Well
each of those classes would have an include for their parent and that's the
problem i'm having. I've compiled the 9 classes, but the main keeps giving
me that redefinition error. In main i had to include formula, variable,
literal, and, or, xor.h.
Formula.h
#include <iostream>
#include "Control.h"
#include<cstring>
using namespace std;
class Literal;
class Formula
ublic Control
{
public:
virtual void print(ostream& os) const=0;
virtual Formula* differentiate(const string& var) const=0;
virtual bool evaluate(bool& val) const=0;
virtual Formula*subst() const=0;
virtual Formula*reduce(const string& var, const Literal* val) const=0;
Control.h
public:
void addRef();
void removeRef() ;
private:
int refCount;
protected:
Control(void);
virtual ~Control(void){;}
===============================================================
Literal.h
#include <iostream>
#include <cstring>
#include "Formula.h"
using namespace std;
class Literal : public Formula
{
private:
bool value;
public:
Literal(bool v);
~Literal(void);
void print(ostream& os) const;
bool evaluate(bool& val) const;
Formula* reduce(void) const;
Formula* differentiate( const string& val ) const;
Formula* subst(const string& var, const Literal* val) const;
};
=======================================================================
Operation.h
#include <iostream>
using namespace std;
#include "Formula.h"
class Operation
ublic Formula
{
public:
protected:
Operation( Formula* l=0, Formula* r=0);
~Operation(void);
Formula * left;
Formula * right;
};
=======================================================================
And.h
#include <iostream>
#include "Operation.h"
using namespace std;
class And : public Operation
{
public:
And(Formula* l, Formula*r): Operation(l,r){}
void print(ostream& os) const;
bool evaluate(bool& val) const;
Formula* reduce(void) const;
Formula* differentiate( const string& var ) const;
};
Thanks in advance
on virtual functions and have to seperate out each class into a file. There
are 9 classes and so 9 .h and .c files. the file structure is something
like this.
control
|
formula
|| |
|| |
|| Operation
|variable |||
literal ||AND
|XOR
OR
So formula inherits from control and operation from formula and etc. Well
each of those classes would have an include for their parent and that's the
problem i'm having. I've compiled the 9 classes, but the main keeps giving
me that redefinition error. In main i had to include formula, variable,
literal, and, or, xor.h.
Formula.h
#include <iostream>
#include "Control.h"
#include<cstring>
using namespace std;
class Literal;
class Formula
{
public:
virtual void print(ostream& os) const=0;
virtual Formula* differentiate(const string& var) const=0;
virtual bool evaluate(bool& val) const=0;
virtual Formula*subst() const=0;
virtual Formula*reduce(const string& var, const Literal* val) const=0;
Control.h
public:
void addRef();
void removeRef() ;
private:
int refCount;
protected:
Control(void);
virtual ~Control(void){;}
===============================================================
Literal.h
#include <iostream>
#include <cstring>
#include "Formula.h"
using namespace std;
class Literal : public Formula
{
private:
bool value;
public:
Literal(bool v);
~Literal(void);
void print(ostream& os) const;
bool evaluate(bool& val) const;
Formula* reduce(void) const;
Formula* differentiate( const string& val ) const;
Formula* subst(const string& var, const Literal* val) const;
};
=======================================================================
Operation.h
#include <iostream>
using namespace std;
#include "Formula.h"
class Operation
{
public:
protected:
Operation( Formula* l=0, Formula* r=0);
~Operation(void);
Formula * left;
Formula * right;
};
=======================================================================
And.h
#include <iostream>
#include "Operation.h"
using namespace std;
class And : public Operation
{
public:
And(Formula* l, Formula*r): Operation(l,r){}
void print(ostream& os) const;
bool evaluate(bool& val) const;
Formula* reduce(void) const;
Formula* differentiate( const string& var ) const;
};
Thanks in advance