先举例:
template <class HashingSolution>
struct State : public HashingSolution {
void Update(int idx, int val) {
UpdateHash(idx, val);
}
int GetState(int idx) {
return ...;
}
};
struct DummyHashingSolution {
void UpdateHash(int idx, int val) {}
void RecalcHash() {}
};
struct MyHashingSolution {
void UpdateHash(int idx, int val) {
...
}
void RecalcHash() {
...
UpdateHash(idx, GetState(idx)); // Problem: no acces to GetState function, can't do recursive application of templates
...
}
};
在此示例中,我可以将 MyHashingSolution 传递给 State 类,因此 State 可以访问 HashingSolution 的方法,但 HashingSolution 不能调用 GetState。有可能解决这个问题吗?
这是最深的循环。这里的虚函数使性能下降了 25% 以上。内联对我来说至关重要。