任何人都可以用vector = vector和class帮助我吗?

时间:2016-12-07 05:48:31

标签: c++

我似乎无法弄清楚如何使用此向量或节点和PCB来运算符=。我知道它是一个过载问题,但每次我做一个不同类型的=它给我一些疯狂的错误与矢量和PCB和其他东西,它让我疯了,所以任何人都有一个提示我如何创建这个,所以它赢了&#39 ;崩溃或给我一个错误?

1 个答案:

答案 0 :(得分:0)

以下是我的方式:

struct PCB
{
[...]
   // assignment operator -- defining this operator isn't really necessary
   // for this particular class since all of the members of this class are
   // held by-value anyway (and thus the compiler-provided default
   // implementation would do exactly the same thing that this implementation
   // does) but I'm leaving it here anyway as example of what a properly
   // constructed assignment operator might look like.
   PCB& operator =(const PCB & b)
   {
      ProcessID     = b.ProcessID;
      ProcessorSize = b.ProcessorSize;
      priority      = b.priority;
      name          = b.name;
      return *this;
   }
};

[...]

printer_cpu[i] = PQ[i].top()->data;