【问题标题】:vector base derived class向量基派生类
【发布时间】:2016-03-30 01:10:02
【问题描述】:

我无法调用所有注册时钟的订阅者的 negedge,所有订阅者也都从 ClkIf 派生

class ClkAdapter : public ClkIf
{
    virtual void negedge() 
    {
        for(std::list<ClkIf*>::iterator it = clk_list.begin(); it != clk_list.end(); it++)
            (it->negedge)();
    }

    virtual void posedge() 
    { clk_cnt++; }

    void registerForClock(ClkIf* module)
    {   clk_list.push_back(module); }

    std::list<ClkIf*> clk_list;        
    unsigned long long clk_cnt;
};

错误:在 '* it.std::_List_iterator<_tp>::operator-> 中请求成员 'negedge',带有 _Tp = ClkIf*',它属于非类类型 'ClkIf*' negedge 函数出错,这段代码有什么问题?

【问题讨论】:

    标签: vector interface stl derived-class base-class


    【解决方案1】:

    您有一个指针列表,因此列表迭代器的工作原理类似双指针(即ClkIf**)。因此,您必须在循环内调用(*it)-&gt;negedge()(*it) 首先获取当前的 ClkIf* 元素,然后 -> 运算符调用 that 值上的函数。

    【讨论】:

    • 现在工作了,真丢人
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 2021-09-27
    • 2020-08-30
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    相关资源
    最近更新 更多