开发者

variable not declared in scope using template inheritance

开发者 https://www.devze.com 2023-04-06 06:08 出处:网络
OMStatic.h template<class Concept> class OMStaticArray : public OMAbstructContainer<Concept> {
OMStatic.h
template<class Concept> class OMStaticArray :
            public OMAbstructContainer<Concept> {
protected:
    Concept *theLink;
    int count;

    void* AllocateMemory(int size);
    bool  ReleaseMemory(void* pMemory);
    //...
};

OMCollec.h

template<class Concept> class OMCollection :
    public OMStaticArray<Concept>{
public:

void add(Concept p) {
    //...


> if (this->count >= size)

    //...
}

In above code, class OMCollection is inherited from OMStaticArray, my understanding is that we can access protected variables directly, but i am getting an error "count not declared in scope". If i u开发者_如何转开发se this->count error is not shown. why i am facing this error, it used to compile in VxWorks 5.5, and now i migrated to Vxworks6.8 i am facing this error if don't use "prefix" before it? what is the reason behnind this ? Please clarify.

Thanks!


This is best explained in the C++ FAQ: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19.

To paraphrase:

Within OMCollection<Concept>::add(), the name count does not depend on template parameter Concept, so count is known as a nondependent name. On the other hand, OMStaticArray<Concept> is dependent on template parameter Concept so OMStaticArray<Concept> is called a dependent name.

Here's the rule: the compiler does not look in dependent base classes (like OMStaticArray<Concept>) when looking up nondependent names (like count).

As to why this compiled in an older compiler, the reason is probably that the older compiler wasn't fully compliant with the C++ standard.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号