<list> iterator error when including "upperclass.h"

Hi,
I have a project with two (involved) classes. A "lowerclass.h" and a "upperclass.h"(has a std::list of lowerclass elements). Until now i only had included lowerclass in upperclass and everything worked fine, but since i included upperclass in lowerclass, my list of lowerclass "is not a valid template type argument for parameter".

1
2
3
4
5
#ifndef LOWERCLASS_H
#define LOWERCLASS_H
#include"upperclass.h"
class lowerclass{...};
#endif 


1
2
3
4
5
6
7
8
9
10
#ifndef UPPERCLASS_H
#define UPPERCLASS_H

#include <list>
#include "lowerclass.h"
class upperclass
{
  std::list<lowerclass> lcs;
};
#endif 
good point nonsence.
You can declare a class before defining it, i.e.
1
2
3
4
5
6
 // do not include lowerclass.h
class lowerclass; // declaration

class upperclass { // definition
 
}


std::list<lowerclass> would not work yet, because it requires a definition ( though std::list<lowerclass*> would ).
I did not find a general solution for this existential issue. Some people say that when this situation arise, it is a symptom of code mess anyway.

Regards,
Dean
Thanks Dean!

I had to declare them both before each other. Didn't know that^^

Topic archived. No new replies allowed.