vector problem

Hi,I have a class contains a function member that takes a vector as a parameter but I cannot assign values to that vector using this function

class in the header file

1
2
3
4
5
6
7
8
9
10
class Cgatetype{
private:
  std::string name;
  std::vector<bool> truthTable_;
              
public:
  Cgatetype() {};
  void set_name(string Cname);
  void set_truthTable(vector<bool> Ctruth);
 


1
2
3
void Cgatetype::set_truthTable(vector<bool> Ctruth){
	truthTable_=Ctruth;
}


I want to assign values to that truthTable vector using

1
2
Cgatetype and2;
and2.set_truthTable(truthTable_.pushback(0));


but I cannot do it in this way, is there any way to assign values to that vector using set_vector function
You might be better off creating unique classes for each type of gate, eg:

1
2
3
4
5
class AND_gate {
};

class OR_gate {
};


then having the class be responsible for constructing the truth table correctly.

This is probably going to require inheritance, polymorphism, and a virtual function or two, so if you are not
familiar with those concepts, then don't even bother.

Now, I'm not real sure how you intend on using the truthTable_ member, given that it is just a vector.
Gates take two binary inputs -- a and b. Are you intending on concatenating the two values to form
an integer which you'll use as an index into the vector?

My header file is fixed, so I can not create unique classes. I want to store only outputs (for example for and gate for 00 01 10 11 inputs I want to store only 0001 in the vector) for not only 2 input gates also n input gates
Topic archived. No new replies allowed.