我一直收到以下错误:
main.cpp: In function ‘int main()’:
main.cpp:41: error: no match for ‘operator=’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul))) = (Cache*)operator new [](((size_t)(((long unsigned int)ASSOC) * 32u)))’
cache.h:2: note: candidates are: Cache& Cache::operator=(const Cache&)
main.cpp:47: error: no match for ‘operator[]’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))[j]’
main.cpp:50: error: no match for ‘operator[]’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))[j]’
main.cpp:52: error: no match for ‘operator[]’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))[j]’
main.cpp:53: error: no match for ‘operator[]’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))[j]’
main.cpp:54: error: no match for ‘operator[]’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))[j]’
main.cpp:55: error: no match for ‘operator[]’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))[j]’
代码如下:
int main() {
int ASSOC, BLOCKSIZE, NO_SETS, SIZE, i, k, l, j;
int NO_INDEXB, NO_BLOCKB, NO_TAGB;
cout << "Please enter Block Size: " << '\n';
cin >> BLOCKSIZE;
cout << " Please enter size: " << '\n';
cin >> SIZE;
cout << " Please enter Associativity: " << '\n';
cin >> ASSOC;
NO_SETS = SIZE / (ASSOC * BLOCKSIZE);
// cout << "No of Sets: " << NO_SETS << '\n';
NO_INDEXB = int(log2(NO_SETS));
// cout << NO_INDEXB <<endl;
NO_BLOCKB = int(log2(BLOCKSIZE));
// cout << NO_BLOCKB <<endl;
NO_TAGB = BLOCKSIZE - NO_INDEXB - NO_BLOCKB;
// cout << NO_TAGB <<endl;
Cache* myCache;
myCache = new Cache[NO_SETS];
for (i = 0; i < NO_SETS; i++)
myCache[i] = new Cache[ASSOC];
for (i = 0; i < NO_SETS; i++) {
for (j = 0; j < ASSOC; j++) {
myCache[i][j].tag = new char(NO_TAGB + 1);
for (k = 0; k < NO_TAGB; k++) {
myCache[i][j].tag[k] = '0';
}
myCache[i][j].LRU = j;
myCache[i][j].valid = 0;
myCache[i][j].dirty = 0;
myCache[i][j].index = i;
}
}
答案 0 :(得分:0)
Cache* myCache;
myCache[i][j].LRU = j;
myCache[i][j]
的含义是什么