0

I've got the two classes below, and the "BitmapIterator" class is refusing to recognize that the "Bitmap" class exists, and I can't figure out why...

I've declared the Bitmap class prior to creating the handle, HBitmap class, and HBitmap is recognized by other classes I'm using.

I've included the header files.

I can't figure out what's going on with this BitmapIterator class... It throws a whole pile of "Bitmap is not a class or a namespace" and "syntax error: identifier HBitmap" errors.

#pragma once
#include "Color.h"

#include "BitmapIterator.h"
#include <list>

namespace BitmapGraphics
{
    class Bitmap;
    using HBitmap = std::shared_ptr<Bitmap>;

    class Bitmap
    {
    public: 
        using ScanLine = std::list<Color>;

    private:
        using ScanLineCollection = std::list<ScanLine>;
        
    public:
        using ScanLineIterator = ScanLineCollection::const_iterator;
        using PixelIterator = ScanLine::const_iterator;
        Bitmap()=default;

        Bitmap(const Bitmap&) = default;
        Bitmap(Bitmap&&) noexcept = default;

        Bitmap& operator=(const Bitmap&) = default;
        Bitmap& operator=(Bitmap&&) = default;

        ~Bitmap() noexcept = default;


        Bitmap(uint32_t width, uint32_t height, std::istream& sourceStream);

        ScanLineIterator begin() const noexcept { return myScanLines.begin(); }
        ScanLineIterator end() const noexcept { return myScanLines.end(); }

        int getWidth() const noexcept { return myWidth; }
        int getHeight() const noexcept { return myHeight; }
        int getNumberOfPadBytes() const;
        
        void read(std::istream& sourceStream);
        void write(std::ostream& destinationStream) const;

        HBitmapIterator createIterator(HBitmap hbitmap);

    private:
        unsigned int myWidth{ 0 };
        unsigned int myHeight{ 0 };

        ScanLineCollection myScanLines;
    };
}

and

#pragma once
#include "IBitmapIterator.h"
#include "Bitmap.h"
#include "binary_ostream_iterator.h"
#include <list>


namespace BitmapGraphics
{
    class BitmapIterator : public IBitmapIterator
    {
    public:
        BitmapIterator() = default;
        BitmapIterator(const BitmapIterator& other) = delete;
        BitmapIterator(BitmapIterator&& other) = delete;
        BitmapIterator& operator =(const BitmapIterator& other) = delete;
        BitmapIterator& operator =(BitmapIterator&& other) = delete;
        ~BitmapIterator() = default;

        BitmapIterator(HBitmap hbitmap);

        void nextScanLine();
        bool isEndOfImage() const;
        void nextPixel();
        bool isEndOfScanLine() const;

        //void addBitmap(HBitmap hbitmap);

        Color getColor() const;

        int getBitmapWidth() const;
        int getBitmapHeight() const;

    private:
        HBitmap myBitmap;
        Bitmap::ScanLineIterator myScanLineIterator;
        Bitmap::PixelIterator myPixelIterator;



    };
}
speroni1
  • 63
  • 1
  • 4

1 Answers1

1

Bitmap.h includes BitmapIterator.h which includes Bitmap.h before it gets to code, which is skipped due to pragma once, then proceeds to use Bitmap before it is defined. Or the other way around.

Header files shouldn't be including each other.

Clean up your dependencies.

Try dropping include of iterator from bitmap and just forward declaring BitmapIterator in the right namespace instead. That may get you started.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524