使用,看起來像一個功能:層疊函數調用
IntegerSet &insert(int m);
我試圖創建一個支持級聯該值插入對象的數組調用的函數。
我的功能:
IntegerSet &IntegerSet::insert(int m) {
IntegerSet newObj;
for (int i = 0; i < 256; i++) {
newObj.set1[i] = set1[i]; //copy the array into the new object
}
newObj.set1[m] = true;
return newObj;
}
被返回的對象是空的,我懷疑有參考做。
試圖通過改變&
改變它看起來像
IntegerSet IntegerSet::&insert(int m)
使得它拒絕編譯,因爲它預計的標識符「。
你返回到本地變量的引用。也許你可以擴展你的例子來包含IntegerSet的定義和你實際使用它的方式。您應該閱讀此:https://stackoverflow.com/questions/4643713/c-returning-reference-to-local-variable –