There seems to be something wrong with the way i pass the variable SCREEN_HEIGHT:
from this class:
class First {
public:
First();
~First();
SDL_Renderer* renderer = NULL;
SDL_Window* gWindow = NULL;
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
};
to this:
class Second {
public:
Second(First f);
int y;
};
and this is the implementation for the classes :
#include "First.h"
First :: First()
: SCREEN_WIDTH(640), SCREEN_HEIGHT(SCREEN_WIDTH/16*9)
{
SDL_Init( SDL_INIT_VIDEO );
SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
gWindow = SDL_CreateWindow( "Testing", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
renderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF );
IMG_Init( IMG_INIT_PNG );
}
First :: ~First()
{
SDL_DestroyRenderer( renderer );
SDL_DestroyWindow( gWindow );
gWindow = NULL;
renderer = NULL;
IMG_Quit();
SDL_Quit();
}
#include "Second.h"
Second :: Second(First f) {
y = f.SCREEN_HEIGHT / 2;
}
this is the main function:
#include "First.h"
#include "Second.h"
#include <iostream>
int main( int argc, char* args[] )
{
First first;
Second second(first);
bool quit = false;
SDL_Event e;
while( !quit )
{
while( SDL_PollEvent( &e ) != 0 )
{
if( e.type == SDL_QUIT )
{
quit = true;
}
}
SDL_SetRenderDrawColor( first.renderer, 0x00, 0x00, 0x00, 0xFF );
SDL_RenderClear( first.renderer );
std::cout << SDL_GetError() << std::endl;
SDL_RenderPresent( first.renderer );
}
return 0;
}