Hello, I found this cool library after months of trying to find a c++ library that I could understand (c++ is my first language) and i've been playing around with it seeing what I can create
Sadly I have run into a problem that I don't know how to solve weather it be due to my lack of c++ experience or with the library itself. My problem is I can't figure out how to use a window that is declared in Class A and use it in Class B, for example.
class A
{
public:
A(); // Constuctor for A
sf::RenderWindow mWindow;
};
A::A()
: mWindow(sf::VideoMode(1200, 720))
{
}
class B : public A
{
void drawSprite
sf::Sprite someSprite;
};
void B::drawSprite()
{
mWindow.draw(someSprite);
// I know there is nothing in someSpite but for the sake of readability lets say there was
}
When I try to create the "drawSprite" function in my code the IDE says that mWindow is an unknown type name. I wish I knew more about classes but my c++ knowledge is limited to a few beginner books. I know this may seem like a really dumb problem but if anyone would be willing to explain to me why this is not working I would be greatly appreciative.
Thanks :)
Ok, I WAS trying to keep the code as simple as possible but ill show my exact code so you can get an idea of what I am trying to do
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
class game
{
public:
game();
// Irellivant functions that draw stuff to mWindow I made are here (they work!)
sf::RenderWindow mWindow;
// Irrelevant sf::Textures and such are here
};
game::game()
: mWindow(sf::VideoMode(1200, 720), Header)
{
// Load up all the textures
}
class MainMenu : public game // inherits all of the members of game
{
MainMenu();
// More irellivant functions
void drawButton();
sf::Sprite button;
sf::Texture buttonTexture
};
MainMenu::MainMenu()
{
// For the sake of simplicity, lets say I loaded the texture and assigned it to the "button" object
}
MainMenu::drawButton()
{
mWindow.draw(button); // this is the exact spot where the error "mWindow is an unknown type name" appears
}
This is where the IDE says it dosent know what mWindow is, I have read all the chapters in my book on classes and I deduced that since i inherited all of "game" public members I should also get "sf::RenderWindow mWindow"
Edit: AH HA! After flipping though my book for a few hours I remembered that the parent constructor is not automatically used! So as far as I could guess I was trying draw something onto something that didn't exist (as it was not initialized).
Well thanks for all your help guys and thanks for your patience