Regarding the last post! It would be really nice (to fit in with my ideas about how to solve my problem) if i could use the method:
Code:
theCircuit.push_back(new AndGate);
I tried to implement this, but i come up with these errors...
Code:
Compiling...
CIRCUIT.CPP
D:\WORK\CIRCUIT.CPP(33) : error C2228: left of '.setInput1' must have class/struct/union type
D:\WORK\CIRCUIT.CPP(34) : error C2228: left of '.setInput2' must have class/struct/union type
D:\WORK\CIRCUIT.CPP(35) : error C2228: left of '.getOutput' must have class/struct/union type
Error executing cl.exe.
CIRCUIT.exe - 3 error(s), 0 warning(s)
Here is how everything is setup...
LogicGate:
Code:
class LogicGate{
private:
int type; // The type of logic gate
int theID; // The ID for the logic gate
int pID1; // The first parent for the logic gate
int pID2; // The second parent for the logic gate
int input1; // The first input value for the logic gate
int input2; // The second input value for the logic gate
int output; // The output value for the logic gate
public:
// use default constructor
// Class Methods:
int getID(); // returns gates ID
int getPID1(); // returns gates first parent ID
int getPID2(); // returns gates second parent ID
void setPID1(int); // sets ID of gates first parent
void setPID2(int); // sets ID of gates second parent
void setInput1(int); // sets gates first input value
void setInput2(int); // sets gates second input value
int getInput1(); // returns value of first input
int getInput2(); // returns value of second input
// Virtual Methods:
//virtual int getOutput(); // returns gates output value
};
AndGate:
Code:
class AndGate : public LogicGate {
public:
// Class methods:
int getOutput();
};
and the file to run a quick test program... [Circuit.cpp]
Code:
#include <vector>
#include <iostream>
using namespace std;
// Include the different types of logic gate that use this class
#include "LogicGate.cpp"
#include "AndGate.cpp"
//#include "OrGate.cpp"
//#include "XorGate.cpp"
//#include "NotGate.cpp"
int main(){
int x,y,z;
vector <LogicGate*> theCircuit(0);
cout<<"enter input 1: ";
cin>>x;
cout<<endl<<"enter input 2: ";
cin>>y;
theCircuit.push_back(new AndGate);
theCircuit.at(0).setInput1(x);
theCircuit.at(0).setInput2(y);
z = theCircuit.at(0).getOutput();
cout<<endl<<"output is: "<<z<<endl;
return 0;
}
I hope that it is just a simple problem!!! ...I am beginning to see light at the end of the tunnel now!!! having not understood a thing about OO Programing (im a low-level C programmer!) Im starting to understand these concepts, and they seem really good!!! ...Just need to learn about how to use them properlly now!!!!! LOL!!!!!
Again... Thanks to everyone that is helping! couldn't do it without you guys!!! ...I just hope i can do the same in the near future!!!!