variable not declared in scope using template inheritance
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 namecount
does not depend on template parameterConcept
, socount
is known as a nondependent name. On the other hand,OMStaticArray<Concept>
is dependent on template parameterConcept
soOMStaticArray<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 (likecount
).
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.
精彩评论