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

Author Topic: Error: Class 'application' does not have any field named 'window'  (Read 3107 times)

0 Members and 1 Guest are viewing this topic.

Servalipp

  • Newbie
  • *
  • Posts: 1
    • View Profile
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!
« Last Edit: June 13, 2019, 07:50:07 pm by Servalipp »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Error: Class 'application' does not have any field named 'window'
« Reply #1 on: June 13, 2019, 09:01:27 pm »
Remove the () from this line: sf::RenderWindow window(); //Creates a window

You also don't need sf::Event as a member, using namespace is not too good of a practice (especially std one), and you can call sf::VideoMode's static functions like: sf::VideoMode::getDesktopMode() instead of the way you do it now (instancing an object just to call a static method).
Back to C++ gamedev with SFML in May 2023