【问题标题】:no match for ‘operator=’ in ‘*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul)))'*(myCache + ((long unsigned int)(((long unsigned int)i) * 32ul))中的'operator='不匹配
【发布时间】:2014-09-17 01:20:02
【问题描述】:

我不断收到以下错误:

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;
        }
    }

【问题讨论】:

  • 至少你应该说明Cache是如何定义的。
  • 分别使用std::vector&lt;Cache&gt;std::vector&lt;std::vector&lt;Cache&gt;&gt;
  • 嘿,我得到了答案
  • 缓存** myCache; myCache = 新缓存*[NO_SETS]; for (i=0;i
  • 您似乎打算将myCache 用作二维数组?

标签: c++ linux


【解决方案1】:
Cache* myCache;

myCache[i][j].LRU = j;

myCache[i][j] 是什么意思

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-27
    • 2016-07-29
    • 1970-01-01
    • 2016-12-20
    • 2013-08-01
    • 1970-01-01
    • 2017-09-10
    • 1970-01-01
    相关资源
    最近更新 更多