Does not name a type
There is a code like this(I work in Code Blocks):
#include <SFML/Graphics.hpp>
class Test
{
sf::Texture testTexture;
testTexture.loadFromFile("sheet1.png");
};
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
This is the usual sfml health check code taken from their site. I added my own Test class to it. When compiling, code blocks throws this error:
main.cpp|6|error: 'testTexture' does not name a type
What can this be related to and in which direction to dig? This is the third day I've been struggling with this error
P.S. without a class, the code compiles perfectly and works
0
1 answers
And what behavior do you expect from your code? What do you think the string{[3] should do?]}
testTexture.loadFromFile("sheet1.png");
Inside the class?
In fact, what you want is done with the constructor . Something like that. The constructor will be called when creating an object of this class.
class Test
{
sf::Texture testTexture;
Test() {
testTexture.loadFromFile("sheet1.png");
}
};
1
Author: retorta, 2017-06-11 10:10:25