SFML community forums

Help => Graphics => Topic started by: wh1t3crayon on October 07, 2014, 03:24:34 am

Title: Problem with VertexArray declaration?
Post by: wh1t3crayon on October 07, 2014, 03:24:34 am
In the tutorial for sf:VertexArrays, this line of code is given as an example declaration:
sf::VertexArray quad(sf::Quads, 4);
However, when I copy and paste this into my own project, like so:
struct Tetromino{
   std::string filename;
   sf::VertexArray quad(sf::Quads, 4);
   // write a constructor taking a string and four vertices
   Tetromino(std::string filename, sf::VertexArray squares);
   ~Tetromino();
};
 
I get the error "constant sf::Quads is not a type name". Why is this happening? Is this a bug or error in the documentation?
Title: Re: Problem with VertexArray declaration?
Post by: binary1248 on October 07, 2014, 03:58:43 am
I copy and paste this into my own project
Don't copy and paste. Understand.
Is this a bug or error in the documentation?
You might want to spend more time, assuming you even spent any, staring at your own code and that error before assuming that this is even remotely SFML's fault.

I might be harsh, but you need to understand the very basics of C++ (http://en.cppreference.com/w/cpp/language/data_members) before using SFML.
Title: Re: Problem with VertexArray declaration?
Post by: wh1t3crayon on October 07, 2014, 05:30:27 am
I copy and paste this into my own project
Don't copy and paste. Understand.
Is this a bug or error in the documentation?
You might want to spend more time, assuming you even spent any, staring at your own code and that error before assuming that this is even remotely SFML's fault.

I might be harsh, but you need to understand the very basics of C++ (http://en.cppreference.com/w/cpp/language/data_members) before using SFML.

Ah, perhaps you didn't understand then. I chose the words "copied and pasted" not because I had no idea what I was doing (this is only true half the time), but because I was emphasizing the fact that I knew I had typed nothing wrong. As for the link, that's great and all that you want me to learn on my own, but as far as the thread goes this does very little. I'm just asking something out of curiosity because it intrigues me, so please answer accordingly.
Title: Re: Problem with VertexArray declaration?
Post by: Laurent on October 07, 2014, 08:05:36 am
The answer is relevant. What you wrote is not correct C++, so you need to learn the language first. Declaring and defining variables is one of the very first steps, so while we could give you the solution directly, we feel like you lack some important C++ skills and would better practice more before doing more complex things with SFML.

Hint for your problem: the tutorial doesn't show a declaration, it's a declaration + definition (construction).
Title: Re: Problem with VertexArray declaration?
Post by: BaneTrapper on October 07, 2014, 06:56:00 pm
Personally i feel you are being too harsh on him even if he is newbie.
But wh1t3crayon, you could search the forums, you would find answer quickly. Also i suggest to read about c++ "struct" and "class".


What you did is not a valid way to declare vertexArray in c++ struct. The declaration should look like this.
Code: [Select]
sf::VertexArray name;
Title: Re: Problem with VertexArray declaration?
Post by: wh1t3crayon on October 08, 2014, 04:47:57 am
Ok looking at it with a clear head I understand the answers. So my issue was that I was (using dumbed down terms) creating an object and constructing it in a class/struct, which isn't allowed in any place other than inside a function? I.e. If I moved that code to inside a function in a cpp file it would work?
Title: Re: Problem with VertexArray declaration?
Post by: Ixrec on October 08, 2014, 08:01:01 am
It would probably go best in the initializer list of Tetronimo's constructor, but yes, the problem is you can't call the constructors of your class' members in a class declaration.