I have this error at "iterator_of_array_int.h":
#include "array_of_int.h"
#include <cstdlib>
namespace leonidandand {
class iterator_of_array_int
{
private:
std::size_t index;
// next line has error
array_of_int * ptr_to_arr;
friend class array_of_int;
};
}
"array_of_int.h"
#pragma once
#include <cstdlib>
#include "iterator_of_array_int.h"
namespace leonidandand {
class array_of_int {
public:
typedef iterator_of_array_int iterator;
iterator_of_array_int begin();
iterator_of_array_int end();
};
}
I included "array_of_int.h". What's wrong???
You included array_of_int.h
which, before defining array_of_int
, included iterator_of_array_int.h
. So when the compiler sees your error line, it hasn't seen any declaration of the name array_of_int
. The error message isn't one of the more helpful ones issued by a compiler.
I'm in the habit of forward-declaring classes in headers; that's all you need in iterator_of_array_int.h
, so replace the include
line with class array_of_int;
and that one's good.