#Why does this not work ?

9 messages · Page 1 of 1 (latest)

magic wren
#

I have a main.cpp file

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include "supp.cpp"

class renderer: public DrawFunctions
{
public:
    bool OnUserCreate() override
    {
        FillScreen(olc::Pixel(255 , 255 , 255));
        DrawAxes(olc::Pixel(0 , 0 , 0));

        return true;
    }

    bool OnUserUpdate(float fElapsedTime) override
    {
        return true;
    }
};

And another file named supp.cpp

#define OLC_PGE_APPLICATION

#include "olcPixelGameEngine.h"

class DrawFunctions : public olc::PixelGameEngine
{
public:

    void FillScreen(olc::Pixel pixel_type)
    {
        for (int i=0 ; i<ScreenHeight() ; i++)
        {
            for (int j=0 ; j<ScreenWidth() ; j++)
            {
                Draw(j , i , pixel_type);
            }
        }
    }

    void DrawAxes(olc::Pixel pixel_type)
    {
        for (int i = 0 ; i<ScreenHeight() ; i++)
        {
            Draw((int)(ScreenWidth() / 2) , i , pixel_type);
        }

        for (int j = 0 ; j<ScreenWidth() ; j++)
        {
            Draw(j , (int)(ScreenHeight() / 2) , pixel_type);
        }
    }
};

why does this not work ?

cursive bridgeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

magic wren
#

i get atleast 500 errors, cannot even put them here

but they are all previous definition and redefinition errors.

#

for eg

      |              ^~~~~~~~~~~~~~~
In file included from main.cpp:2:
olcPixelGameEngine.h:6602:14: note: ‘virtual void olc::PixelGameEngine::olc_ConfigureSystem()’ previously defined here
 6602 |         void PixelGameEngine::olc_ConfigureSystem()
cunning blaze
#

#include "supp.cpp"
Don't include a cpp file?

magic wren
#

yeah i tried to then put that stuff in a header file and compile supp.cpp separately and then link against it

#

idk what goes in the header file ?

cunning blaze
#

Optimally you should only put function declarations in a header file

#

With implementations of those functions in a separate cpp