So I am writing a simple project but something doesn't work and I am really stumped. (This is the second time I'm writing this.. I don't think the first one posted...
Anyways... here is the code.
application.h
#ifndef APPLICATION_H
#define APPLICATION_H
#include "ball.h"
#include <SFML/Graphics.hpp>
#include <string>
class application
{
public:
application();
int getWINDW();
int getWINDH();
void drawApplication(ball bll);
protected:
int SCRW, SCRH, WINDW, WINDH;
private:
sf::Event event;
sf::RenderWindow window(); //Creates a window
};
#endif // APPLICATION_H
application.cpp
#include "application.h"
#include <SFML/Graphics.hpp>
#include <iostream>
//-----user defined headers------
#include "ball.h"
#include "background.h"
//--------------------------------
using namespace sf;
using namespace std;
application::application() : window(VideoMode(int WINDW, int WINDH), "Rebounce v.0")
{
SCRW = VideoMode().getDesktopMode().width;
SCRH = VideoMode().getDesktopMode().height;
WINDW = SCRW/1.2;
WINDH = SCRH/1.2;
cout << "Current Screen W&H are: " << SCRW << ", " << SCRH << endl;
cout << "Current Window W&H are: " << WINDW << ", " << WINDH << endl;
}
int application::getWINDW()
{
return WINDW;
}
int application::getWINDH()
{
return WINDH;
}
void application::drawApplication(ball bll)
{
//run the program as long as the window is open
while (window.isOpen)
{
// check all the window's events that were triggered since the last iteration of the loop
//whatever that means
while (window.pollEvent(event))
{
//"close requested" event: we close the window
if (event.type == Event::Closed)
{
window.close();
}
}
window.clear();
window.draw(bll);
window.display();
}
}
main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
//-----user defined headers------
#include "application.h"
//--------------------------------
using namespace sf;
using namespace std;
int main()
{
application app;
ball bll;
bll.setMiddle(app.getWINDW(), app.getWINDH());
app.drawApplication(bll);
return 0;
}
I get an error on application.cpp on line 12, telling me "error: clas 'application' does not have any field named 'window'
I was stumped, so I made a test program to see if it was c++ or the libraries, and this one worked.
Code:
#include <iostream>
using namespace std;
class otherclass
{
public:
void hello()
{
cout << "heo" << endl;
}
};
class classnotworking
{
public:
otherclass thing;
void useOtherClass()
{
thing.hello();
}
private:
};
int main()
{
classnotworking bleh;
bleh.useOtherClass();
return 0;
}
Thank you all very much for your help!