Creating vectors of objects!
I have posted earlier today more about my project! I have now sorted out the compile errors with the include files! I worked out that unlike Java or C, for a whole C++ project you only need to write #include "file.cpp" in any one of the files, if you do mulitple include statements for a file (not a library function) it see's it as a redeclaration for some uknown reason!!!
Anywayz; I have now come up to another problem!!! Basically, here is my design;
are all classes that inherit common functions from the class LogicGate. My idea was that i could then create a vector to store logic gates of different types in the same place, and therefore have easy tracking of the circuits components! However, When I do this, you can insert instances of the inheritted classes into the vector, but you can't access the added functionality of them!!!
Does anyone know if this is possible???
then functions for gettting and setting pid's, id, inputs, etc. are standard for all logic gates
AndGate, XorGate, OrGate & NotGate all overide the LogicGate function;
getOutput - calculates the output depending on the input values supplied to the object.
So basically, I do the following;
This doesn't seem to be working, but I can assure you that the logic gate classes are all working because i have spent all day checking this to get it perfect!!! ...My only problem is finding a way to store the different gates!
// Create some objects of different gates for testing!
vector <LogicGate> myCircuit(0); // start off circuit empty
// add the objects to the vector
// Set the input values for the gates:
myCircuit.at(3).setInputs(1); // NOT GATE - Only one input!!! - function over-riding in use.
// Now get the outputs for the gates:
int a = myCircuit.at(0).getOutput();
int b = myCircuit.at(0).getOutput();
int c = myCircuit.at(0).getOutput();
int d = myCircuit.at(0).getOutput();
// write outputs...
cout<<"and: "<<a<<endl<<"or: "<<b<<endl<<"xor: "<<c<<endl<<"not: "<<d<<endl;
I thought that by doing it this way, it would work because the getOutput function in class LogicGate is over-ridden by the AndGate, OrGate, NotGate and XorGate classes so in effect all objects within the vector would be the same!!! Obviously i am wrong!!! any guidance, much appriciated!!! Thanks!!! Matt