Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Excellent

Pages: [1]
1
Window / Re: Using a window though multiple classes
« on: March 16, 2014, 04:48:41 pm »
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

2
Window / Re: Using a window though multiple classes
« on: March 16, 2014, 04:22:21 am »
Thanks for your help zsb, as I stated earlier it says that mWindow is an unknown type name, I've checked and mWindow is in class A AND it is under the "public" namespace. Im using Xcode on a mac, if that helps at all, im guessing what it means by unknown type name is that it cannot find where I declared "mWindow" but I have no idea why.

Before I was using sf::RenderWindow "mWindow" in class 'A' but i've tried just sf::Window mWindow as well and it still telling me that class B doesn't know what 'mWindow' is (unknown type name).

As far as I can tell i've followed the tutorial to the tee and I can draw stuff to mWindow as long as it is with a function that is in class A

Sorry for wasting your time, I wish i knew if this is a problem because I don't have a proper understanding of c++ or because I don't have a proper understanding of SFML, thanks again atleast i'm learning  :)

3
Window / Re: Using a window though multiple classes
« on: March 16, 2014, 02:58:14 am »
So if a even if I declare "mWindow" in A's constructor (which I placed in the "public" area) it still makes "mWindow" private thus making the inheritance not work because it only inherits public members?

So a solution to this would be to create a "sf::Window mWindow" inside the "public" area of A then in the constructor make a "sf::Window mWindow2" then render it and copy it to "mWindow" thus making it available  for B to have stuff rendered onto it?

Again sorry that I am unsure, I assumed placing the constructor in the "public" would give B access to it

Edit: facepalm on myself, I placed the "public:" in the wrong spot on my original post but it is the right spot now so it matches with my code, but I still dont understand why the IDE gives me an error

4
Window / Using a window though multiple classes
« on: March 16, 2014, 12:58:45 am »
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  :)

Pages: [1]
anything