*** was not declared in this scope

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

#include <ostream.h>
#include <assert.h>

template<class T> struct GiSTlistnode;

template <class T>
class list{
public:
list(): count(0), front(NULL), rear(NULL) {}
int IsEmpty() const { return front==NULL; }
virtual void Insert(T entry) const{ Append(entry); }
unsigned int Count() const { return count; }
//
//cut
//
#ifdef PRINTING_OBJECTS
void Print(ostream& os) const {
GiSTlistnode<T> *temp=front;

os << "List entries:\n";
while(temp) {
os << "\t" << temp->entry;
temp=temp->next;
}
os << endl;
}
#endif
protected:
//
//cut
//
unsigned int count;
GiSTlistnode<T> *front, *rear;
};

template <class T>
class orderedlist: public list<T>{
public:
orderedlist(int func(T, T)): compare(func), list<T>() { }

virtual void Insert(T entry) {
GiSTlistnode<T> *temp=front;
//
//cut
//
}

private:
void InsertAfter(GiSTlistnode<T> *node, T entry) {
GiSTlistnode<T> *temp=new GiSTlistnode<T>;

temp->entry=entry;
temp->prev=node;
temp->next=node->next;
node->next=temp;
if(rear==node) rear=temp;
else temp->next->prev=temp;
}

void InsertBefore(GiSTlistnode<T> *node, T entry) {
GiSTlistnode<T> *temp=new GiSTlistnode<T>;

temp->entry=entry;
temp->prev=node->prev;
temp->next=node;
node->prev=temp;
if(front==node) front=temp;
else temp->prev->next=temp;
}
//
//cut
//

};

#endif

I wrote the code again:

#ifndef LIST_H
#define LIST_H

#include <ostream.h>
#include <assert.h>

template<class T> struct GiSTlistnode;

template <class T>
class list{
public:
list(): count(0), front(NULL), rear(NULL) {}
int IsEmpty() const { return front==NULL; }
virtual void Insert(T entry) const{ Append(entry); }
unsigned int Count() const { return count; }
//
//cut
//
#ifdef PRINTING_OBJECTS
void Print(ostream& os) const {
GiSTlistnode<T> *temp=front;

os << "List entries:\n";
while(temp) {
os << "\t" << temp->entry;
temp=temp->next;
}
os << endl;
}
#endif
protected:
//
//cut
//
unsigned int count;
GiSTlistnode<T> *front, *rear;

};

template <class T>
class orderedlist: public list<T>{
public:
orderedlist(int func(T, T)): compare(func), list<T>() { }

virtual void Insert(T entry) {
GiSTlistnode<T> *temp=front;
//
//cut
//
}

private:
void InsertAfter(GiSTlistnode<T> *node, T entry) {
GiSTlistnode<T> *temp=new GiSTlistnode<T>;

temp->entry=entry;
temp->prev=node;
temp->next=node->next;
node->next=temp;
if(rear==node) rear=temp;
else temp->next->prev=temp;
}

void InsertBefore(GiSTlistnode<T> *node, T entry) {
GiSTlistnode<T> *temp=new GiSTlistnode<T>;

temp->entry=entry;
temp->prev=node->prev;
temp->next=node;
node->prev=temp;
if(front==node) front=temp;
else temp->prev->next=temp;
}
//
//cut
//

};

#endif
front is not a member of class orderedlist. Neither is rear.
@kbw, thanks for your reply.
but orderlist is a child class of class list (front and rear are member of list)
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 ();
	}


The full page is here
http://gcc.gnu.org/gcc-3.4/changes.html
Last edited on
@guesgulkan thanks!!! the errors are gone. really thanks.
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.
Topic archived. No new replies allowed.