我知道类似的问题曾被问过,但我似乎无法解决我的问题,使用他们的任何一个信息。
我想要达到的目标:,我必须实现一个表(PRTable),它包含PREntry对象。我在c++中的实现如下
class PREntry{
public:
PREntry()
{
Timestamp = 0;
rd_or_wr = 0;
complete = 0;
addr = 0;
}
PREntry(Addr addr, Tick ts, bool rd_wr, bool complete)
{
Timestamp = ts;
rd_or_wr = rd_wr;
complete = complete;
addr = addr;
}
Tick Timestamp;
bool rd_or_wr;
bool complete;
Addr addr;
private :
PREntry& operator=(const PREntry& obj);
};我的PRTable如下所示
class PRTable
{
public:
// Constructor
PRTable(int number_of_PREs){
m_number_of_PREs = number_of_PREs ;
entry.assign(16, PREntry());
}
// Destructor
~PRTable();
std::vector<PREntry> entry;
bool isComplete(MachineID mID);
void insertRequest(Addr addr, MachineID mID, Tick ts, bool rd_wr, bool complete);
void deleteRequest(MachineID mID);
// Print cache contents
void print(std::ostream& out) const;
private:
// PREntry *entry = new PREntry[m_number_of_PREs];
// PREntry *entry[16];
int m_number_of_PREs;
PRTable& operator=(const PRTable& obj);
// PREntry operator[](MachineID mID){return entry[mID];}
// typedef std::map<MachineID,L1Cache_PRE> MachineIDMap;
// MachineIDMap m_map;
};最后是.cc文件
using namespace std;
bool
PRTable::isComplete(MachineID mID)
{
return entry[mID].complete;
}
void
PRTable::insertRequest(Addr addr, MachineID mID, Tick ts, bool rd_wr , bool complete)
{
PREntry pre(addr,ts,rd_wr,complete);
entry[mID] = pre;
}
void
PRTable::deleteRequest(MachineID mID)
{
entry[mID].complete = 1;
} 当我运行代码时,我会看到大量的错误,但我觉得主要的问题是这个错误消息:
build/X86_MOESI_NoMig_token/mem/ruby/structures/PRTable.cc:36:14: error: no match for 'operator[]' (operand types are 'std::vector<PREntry>' and 'MachineID')
return entry[mID].complete;在网上进行了一些研究之后,我发现operator[]不是为一个对象数组定义的,这就是为什么我决定在向量类中已经定义了[]的向量。任何帮助都会很好。我想了解这样的场景通常是如何在c++中设计和编码的。
发布于 2017-11-26 15:06:27
基于上面的代码,错误是向量的[]运算符没有被重载以接受MachineID类型。
https://stackoverflow.com/questions/47497441
复制相似问题