A little old fashion error, maybe.
But I've googled it and found nothing.
I really hope someone could help me.
Thanks.
***.h: In member function ‘virtual void orderedlist<T>::Insert(T)’:
***.h:*: error: ‘front’ was not declared in this scope
***.h: In member function ‘void orderedlist<T>::InsertAfter(GiSTlistnode<T>*, T)’:
***.h:*: error: ‘rear’ was not declared in this scope
***.h: In member function ‘void orderedlist<T>::InsertBefore(GiSTlistnode<T>*, T)’:
***.h:*: error: ‘front’ was not declared in this scope
Below is the code(error lines are bold typed):
#ifndef LIST_H
#define LIST_H
Although front and rear are members of the base class list template class and you would
expect them to be accessible by the derived template class in the normal way - here is the reason (from the GNU website,) why your program gives errors:
In a template definition, unqualified names will no longer find members of a dependent base (as specified by [temp.dep]/3 in the C++ standard).
For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void h ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent, e.g. by prefixing them with this->. Here is the corrected definition of C<T>::h,
template <typename T> void C<T>::h ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
I read all the temp.dep references in the standard, but couldn't see how the descriptions there override the rules in 3.4.1 with example
1 2 3 4 5 6 7 8 9 10 11 12 13
namespace A {
namespace N {
void f();
}
}
void A::N::f() {
i = 5;
// The following scopes are searched for a declaration of i:
// 1) outermost block scope of A::N::f, before the use of i
// 2) scope of namespace N
// 3) scope of namespace A
// 4) global scope, before the definition of A::N::f
}
I'll take is as given gcc is correct, but it's not obvious to me why.