2016-12-07 53 views
-3

我似乎無法弄清楚如何使這個矢量或節點和PCB的運營商=。我知道這是一個過載問題,但每次我做出不同類型=它給我一些與矢量和PCB和其他東西一個瘋狂的錯誤,它讓我瘋狂,所以任何人都得到了一個提示,我如何創建這個,所以它不會崩潰或給我一個錯誤?任何人都可以用vector和class來幫助我嗎?

+0

賦值操作符必須是成員函數。 –

+0

我試圖把內部電路板,但它崩潰使用布爾運算符= – darkflames363

+0

我[這個答案](http://stackoverflow.com/a/4421719/434551)[在SO上的高度投票的問題](http:// stackoverflow.com/questions/4421706/operator-overloading)。 –

回答

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; 
+0

目前尚不清楚爲什麼你想要實現賦值操作符。也許你可以解釋一下嗎? – juanchopanza

+0

:它工作,但然後它崩潰即時猜測在printer_cpu [i] .top()部分 – darkflames363

+0

@juanchopanza問題是關於實現賦值運算符,所以它似乎是一個示例顯示如何做到這一點會有所幫助。 –

相關問題