solving an error in my code

Hello
In my code there are 3 classes, in 2 of them i have STL lists from the type of the other class
Explanation: Class 1 has STL list from type class 2 and Class 2 has STL list from type Class 3.
And i get an error: error C2065: 'Brand' : undeclared identifier c:\users\hebrew\documents\visual studio 2010\projects\test\test\system.h


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
#include<string>
#include"Product.h"
#include"Brand.h"
#include<algorithm>
#include<list>
using namespace std;

  class System {
private:
	string personName;
	string proNum;
	string dayNumber;
	list<Brand> Brands;


What function can be missing?
Thank you
Last edited on
Can we see Brand.h and Product.h?
#ifndef _BRAND_H
#define _BRAND_H

#include<iostream>
#include<algorithm>
#include<list>
#include<string>
#include"Product.h"
using namespace std;



class Brand {
private:
string BrandName;
list <Product> products;
public:

Brand();
Brand& operator=(const Brand &br);
int operator==(const Brand &br) const;
bool SearchProduct(long Id,string BrandName); //returns true if product found
void addProduct(string Brandname, long id);

};

#endif //_BRAND_H



#ifndef _PRODUCT_H
#define _PRODUCT_H

#include<iostream>
#include<string>
#include"System.h"
#include<algorithm>
#include<list>
using namespace std;

class Product {
private:
int productId;
string proName;
double productPrice;
double quantity;
int numOfProducts;
double profit;

public:
Product(int Id=0, string name=" ", double price=0, double quan=0);
int getProductId(int id);
string getproName(string name);
int getNumofProducts() const{return numOfProducts;}
double getProductPrice(double price);
double getQuantity(double quan);
Product& operator=(const Product &br);



};
#endif //_PRODUCT_H
you cannot include System.h in Product.h and then Product.h in System.h
you cannot include System.h in Product.h and then Product.h in System.h

You can, because the header guards will prevent infinitely recursive header file inclusion.

Having said that, I don't understand why Product.h includes System.h, because I can't see anywhere in the posted code where the contents of Product.h depend on the contents of System.h.

Of course, this would be easier if the OP would use code tags to make the code more readable.

EDIT: I would also strongly advise against having using namespace std; in a header file.
Last edited on
MikeyBoy wrote:
You can, because the header guards will prevent infinitely recursive header file inclusion.
Which also means that one will see the other as undefined.
Last edited on
Which also means that one will see the other as undefined.

Yes, and it's usually an indication that there's a problem with the design of your code.

As I said, though, in the OP's case, I think it's just a mistake. There's nothing in Product.h that uses anything in System.h, so there's no actual cyclic dependency that I can see.
The mistake is the extraneous #include ;)
You are right i fixed all includes and it worked
Thank you very much:)))
Topic archived. No new replies allowed.