No appropiate default constructor available












-1















I'm getting an error that says:




SZ_GameItem - No appropriate default constructor available.




Here's parts of the codes:



main.cpp:



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

#include "SZ_GameItem.h"
SZ_GameItem exampleItem;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
examplePlayer.Init();
while (!done)
{
aTimer.resetTicksTimer();

examplePlayer.Update();
examplePlayer.Input();

exampleItem.Update();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
exampleItem.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}


SZ_GameItem.cpp:



#include "SZ_GameItem.h"

SZ_GameItem::SZ_GameItem(int eX, int eY, int eW, int eH)
{
x = eX;
y = eY;
height = eH;
width = eW;

rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

velocity.x = 1;
velocity.y = 0;
}

SZ_GameItem::~SZ_GameItem()
{

}

void SZ_GameItem::Input()
{

}

void SZ_GameItem::Update()
{
rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

x = x + velocity.x;
y = y + velocity.y;
}

void SZ_GameItem::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, 255, 255, 255, 255);
SDL_RenderDrawRect(pRenderer, &rect);
}


SZ_GameItem.h:



#ifndef aGameItem
#define aGameItem

#include <iostream>
#include "SDL.h"
#include "SZ_Vector2D.h"

class SZ_GameItem
{
public:
SZ_GameItem(int x, int y, int w, int h);
~SZ_GameItem();

void Update();
void Input();
void Render(SDL_Renderer* aRenderer);

SZ_Vector2D velocity;
int x, y, height, width;

private:
SDL_Rect rect;
};

#endif


Any help?










share|improve this question

























  • You did not provide a default constructor. you have to add a defaut one (which takes no arguments )

    – Blood-HaZaRd
    Nov 22 '18 at 16:09


















-1















I'm getting an error that says:




SZ_GameItem - No appropriate default constructor available.




Here's parts of the codes:



main.cpp:



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

#include "SZ_GameItem.h"
SZ_GameItem exampleItem;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
examplePlayer.Init();
while (!done)
{
aTimer.resetTicksTimer();

examplePlayer.Update();
examplePlayer.Input();

exampleItem.Update();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
exampleItem.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}


SZ_GameItem.cpp:



#include "SZ_GameItem.h"

SZ_GameItem::SZ_GameItem(int eX, int eY, int eW, int eH)
{
x = eX;
y = eY;
height = eH;
width = eW;

rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

velocity.x = 1;
velocity.y = 0;
}

SZ_GameItem::~SZ_GameItem()
{

}

void SZ_GameItem::Input()
{

}

void SZ_GameItem::Update()
{
rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

x = x + velocity.x;
y = y + velocity.y;
}

void SZ_GameItem::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, 255, 255, 255, 255);
SDL_RenderDrawRect(pRenderer, &rect);
}


SZ_GameItem.h:



#ifndef aGameItem
#define aGameItem

#include <iostream>
#include "SDL.h"
#include "SZ_Vector2D.h"

class SZ_GameItem
{
public:
SZ_GameItem(int x, int y, int w, int h);
~SZ_GameItem();

void Update();
void Input();
void Render(SDL_Renderer* aRenderer);

SZ_Vector2D velocity;
int x, y, height, width;

private:
SDL_Rect rect;
};

#endif


Any help?










share|improve this question

























  • You did not provide a default constructor. you have to add a defaut one (which takes no arguments )

    – Blood-HaZaRd
    Nov 22 '18 at 16:09
















-1












-1








-1








I'm getting an error that says:




SZ_GameItem - No appropriate default constructor available.




Here's parts of the codes:



main.cpp:



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

#include "SZ_GameItem.h"
SZ_GameItem exampleItem;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
examplePlayer.Init();
while (!done)
{
aTimer.resetTicksTimer();

examplePlayer.Update();
examplePlayer.Input();

exampleItem.Update();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
exampleItem.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}


SZ_GameItem.cpp:



#include "SZ_GameItem.h"

SZ_GameItem::SZ_GameItem(int eX, int eY, int eW, int eH)
{
x = eX;
y = eY;
height = eH;
width = eW;

rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

velocity.x = 1;
velocity.y = 0;
}

SZ_GameItem::~SZ_GameItem()
{

}

void SZ_GameItem::Input()
{

}

void SZ_GameItem::Update()
{
rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

x = x + velocity.x;
y = y + velocity.y;
}

void SZ_GameItem::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, 255, 255, 255, 255);
SDL_RenderDrawRect(pRenderer, &rect);
}


SZ_GameItem.h:



#ifndef aGameItem
#define aGameItem

#include <iostream>
#include "SDL.h"
#include "SZ_Vector2D.h"

class SZ_GameItem
{
public:
SZ_GameItem(int x, int y, int w, int h);
~SZ_GameItem();

void Update();
void Input();
void Render(SDL_Renderer* aRenderer);

SZ_Vector2D velocity;
int x, y, height, width;

private:
SDL_Rect rect;
};

#endif


Any help?










share|improve this question
















I'm getting an error that says:




SZ_GameItem - No appropriate default constructor available.




Here's parts of the codes:



main.cpp:



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

#include "SZ_GameItem.h"
SZ_GameItem exampleItem;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
examplePlayer.Init();
while (!done)
{
aTimer.resetTicksTimer();

examplePlayer.Update();
examplePlayer.Input();

exampleItem.Update();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
exampleItem.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}


SZ_GameItem.cpp:



#include "SZ_GameItem.h"

SZ_GameItem::SZ_GameItem(int eX, int eY, int eW, int eH)
{
x = eX;
y = eY;
height = eH;
width = eW;

rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

velocity.x = 1;
velocity.y = 0;
}

SZ_GameItem::~SZ_GameItem()
{

}

void SZ_GameItem::Input()
{

}

void SZ_GameItem::Update()
{
rect.x = x;
rect.y = y;
rect.h = height;
rect.w = width;

x = x + velocity.x;
y = y + velocity.y;
}

void SZ_GameItem::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, 255, 255, 255, 255);
SDL_RenderDrawRect(pRenderer, &rect);
}


SZ_GameItem.h:



#ifndef aGameItem
#define aGameItem

#include <iostream>
#include "SDL.h"
#include "SZ_Vector2D.h"

class SZ_GameItem
{
public:
SZ_GameItem(int x, int y, int w, int h);
~SZ_GameItem();

void Update();
void Input();
void Render(SDL_Renderer* aRenderer);

SZ_Vector2D velocity;
int x, y, height, width;

private:
SDL_Rect rect;
};

#endif


Any help?







c++ error-handling sdl velocity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 6:27









genpfault

41.9k95298




41.9k95298










asked Nov 22 '18 at 16:02









MistyistyMistyisty

254




254













  • You did not provide a default constructor. you have to add a defaut one (which takes no arguments )

    – Blood-HaZaRd
    Nov 22 '18 at 16:09





















  • You did not provide a default constructor. you have to add a defaut one (which takes no arguments )

    – Blood-HaZaRd
    Nov 22 '18 at 16:09



















You did not provide a default constructor. you have to add a defaut one (which takes no arguments )

– Blood-HaZaRd
Nov 22 '18 at 16:09







You did not provide a default constructor. you have to add a defaut one (which takes no arguments )

– Blood-HaZaRd
Nov 22 '18 at 16:09














1 Answer
1






active

oldest

votes


















2














When you write this line:



SZ_GameItem exampleItem;


you actually declare and initialize a variable of type SZ_GameItem. And in this case, it implicitly initializes the variable using the default constructor (that is, which takes no argument), but you haven't provided one. A default constructor can be implicitly defined in some cases, but as you provided a user-defined constructor, with signature SZ_GameItem(int x, int y, int w, int h), the default constructor is not implicitly defined.



What needs be done is to either initialize this variable yourself using the constructor your provided, or provide a default constructor.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434639%2fno-appropiate-default-constructor-available%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    When you write this line:



    SZ_GameItem exampleItem;


    you actually declare and initialize a variable of type SZ_GameItem. And in this case, it implicitly initializes the variable using the default constructor (that is, which takes no argument), but you haven't provided one. A default constructor can be implicitly defined in some cases, but as you provided a user-defined constructor, with signature SZ_GameItem(int x, int y, int w, int h), the default constructor is not implicitly defined.



    What needs be done is to either initialize this variable yourself using the constructor your provided, or provide a default constructor.






    share|improve this answer






























      2














      When you write this line:



      SZ_GameItem exampleItem;


      you actually declare and initialize a variable of type SZ_GameItem. And in this case, it implicitly initializes the variable using the default constructor (that is, which takes no argument), but you haven't provided one. A default constructor can be implicitly defined in some cases, but as you provided a user-defined constructor, with signature SZ_GameItem(int x, int y, int w, int h), the default constructor is not implicitly defined.



      What needs be done is to either initialize this variable yourself using the constructor your provided, or provide a default constructor.






      share|improve this answer




























        2












        2








        2







        When you write this line:



        SZ_GameItem exampleItem;


        you actually declare and initialize a variable of type SZ_GameItem. And in this case, it implicitly initializes the variable using the default constructor (that is, which takes no argument), but you haven't provided one. A default constructor can be implicitly defined in some cases, but as you provided a user-defined constructor, with signature SZ_GameItem(int x, int y, int w, int h), the default constructor is not implicitly defined.



        What needs be done is to either initialize this variable yourself using the constructor your provided, or provide a default constructor.






        share|improve this answer















        When you write this line:



        SZ_GameItem exampleItem;


        you actually declare and initialize a variable of type SZ_GameItem. And in this case, it implicitly initializes the variable using the default constructor (that is, which takes no argument), but you haven't provided one. A default constructor can be implicitly defined in some cases, but as you provided a user-defined constructor, with signature SZ_GameItem(int x, int y, int w, int h), the default constructor is not implicitly defined.



        What needs be done is to either initialize this variable yourself using the constructor your provided, or provide a default constructor.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 16:15

























        answered Nov 22 '18 at 16:05









        JBLJBL

        9,72333667




        9,72333667






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434639%2fno-appropiate-default-constructor-available%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'