No appropiate default constructor available
up vote
-1
down vote
favorite
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
add a comment |
up vote
-1
down vote
favorite
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
You did not provide a default constructor. you have to add a defaut one (which takes no arguments )
– Blood-HaZaRd
Nov 22 at 16:09
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
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
c++ error-handling sdl velocity
edited Nov 23 at 6:27
genpfault
41.3k95197
41.3k95197
asked Nov 22 at 16:02
Mistyisty
234
234
You did not provide a default constructor. you have to add a defaut one (which takes no arguments )
– Blood-HaZaRd
Nov 22 at 16:09
add a comment |
You did not provide a default constructor. you have to add a defaut one (which takes no arguments )
– Blood-HaZaRd
Nov 22 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 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 at 16:09
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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.
add a comment |
up vote
2
down vote
accepted
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.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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.
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.
edited Nov 22 at 16:15
answered Nov 22 at 16:05
JBL
9,66333667
9,66333667
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You did not provide a default constructor. you have to add a defaut one (which takes no arguments )
– Blood-HaZaRd
Nov 22 at 16:09