0

我有两个类,“缓存”和“LRU”:类缓存看起来像这样:

class cache
{
  private:
    int num_cold;                               //Number of cold misses
    int num_cap;                               //Number of capacity misses
    int num_conf;                               //Number of conflict misses
    int miss;                                   //Number of cache misses
    int hits;                                   //Number of cache hits

  public:
           // methods
}

我也在 LRU 类中有一个方法

bool LRU::access (Block block)
{
  for (i = lru.begin(); i != lru.end(); i++)               //If 
  {
    if (i->get_tag() == block.get_tag() && i->get_index() == block.getIndex()) 
    {
      lru.push_back(block);
      lru.erase(i);
      return true;
      //Here i want to add 1 to the value of variable "hits" of class "cache"
    }
  }
}

我想在“LRU::access”方法中增加“缓存”类中变量的值。有人可以告诉我我该怎么做。谢谢。

4

2 回答 2

4

将此添加到cache

friend class LRU;

将允许任何代码LRU访问.cache

于 2013-06-28T14:42:05.887 回答
0

您可以将 LRU 声明为要缓存的友元类。

于 2013-06-28T14:44:26.937 回答