对于最近的课堂项目,我们需要在MIPS模拟器中的现有课堂方法中修改代码。我成功完成了任务,但是我真的不必理解方法定义,这使我感到困扰。
template<class State, class Addr_t, bool Energy>
typename CacheAssoc<State, Addr_t, Energy>::Line
*CacheAssoc<State, Addr_t, Energy>::findLine2Replace(Addr_t addr, bool ignoreLocked)
{
o
o
o
有很多事情要做。你能帮我分解一下吗?
这是标题的链接:https://github.com/masc-ucsc/esesc/blob/master/misc/libsuc/CacheCore.h
以下是代码文件的链接:https://github.com/masc-ucsc/esesc/blob/master/misc/libsuc/CacheCore.cpp
答案 0 :(得分:2)
这是模板类findLine2Replace
的{{1}}方法的定义(包括省略的花括号中的所有内容)。
CacheAssoc
这些是模板参数,前两个是类型模板参数,最后一个是布尔参数(只能为true或false)。这应该与类定义中显示的相同。
template<class State, class Addr_t, bool Energy>
这是函数返回类型。 typename CacheAssoc<State, Addr_t, Energy>::Line*
关键字是必需的,因为typename
是从属类型,它依赖于未知的模板参数。 CacheAssoc
必须是在::Line
类中定义的类型。
CacheAssoc
是函数名称和参数列表。如果要在CacheAssoc<State, Addr_t, Energy>::findLine2Replace(Addr_t addr, bool ignoreLocked)
类的范围内定义此方法,则CacheAssoc
并不需要以下内容,但是并非如此,所以有必要。