test.cpp:7:35: error: expected ‘)’ before numeric constant
sf::Window window(sf::VideoMode(600,400), "Title");
^
test.cpp:7:35: error: expected ‘)’ before numeric constant
test.cpp:7:34: error: expected ‘;’ at end of member declaration
sf::Window window(sf::VideoMode(600,400), "Title");
^
test.cpp:7:35: error: expected unqualified-id before numeric constant
sf::Window window(sf::VideoMode(600,400), "Title");
^
test.cpp: In member function ‘void Control::run()’:
test.cpp:12:17: error: ‘((Control*)this)->Control::window’ does not have class type
while (window.isOpen()){
^
test.cpp:14:17: error: ‘((Control*)this)->Control::window’ does not have class type
while(window.pollEvent(event)){
^
test.cpp:16:13: error: ‘((Control*)this)->Control::window’ does not have class type
window.close();
^
test.cpp:20:11: error: ‘((Control*)this)->Control::window’ does not have class type
window.display();
^
test.cpp: In function ‘int main2()’:
test.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
I initially did have that. I as well get this error when its in the constructor
1 2 3 4 5 6 7 8 9 10 11
test.cpp: In member function ‘void Control::run()’:
test.cpp:14:20: error: ‘window’ was not declared in this scope
while (window.isOpen()){
^
test.cpp:21:30: error: request for member ‘restart’ in ‘clock’, which is of non-class type ‘clock_t()throw () {aka longint()throw ()}’
time = clock.restart();
^
test.cpp: In function ‘int main2()’:
test.cpp:55:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
You were right to have the declarations where you had them. It's just that initialization bit (the stuff that has to do your window object and everything in parantheses) needs to be taken care of in the constructor.
i didnt know that you had to initialize it in the constructor and declare only where i had it. However i am not sure why as doing the same with an int for example has no problem?
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
class Klass{
public:
int var = 123;
};
int main(){
Klass obj;
std::cout << obj.var;
}
but yet you cannot do?
1 2 3 4 5
class Klass{
public:
sf::Window window(sf::VideoMode(600,400), "Title");
};