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

Author Topic: Problem with VertexArray declaration?  (Read 4202 times)

0 Members and 1 Guest are viewing this topic.

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Problem with VertexArray declaration?
« 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?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Problem with VertexArray declaration?
« Reply #1 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++ before using SFML.
« Last Edit: October 07, 2014, 04:01:58 am by binary1248 »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Problem with VertexArray declaration?
« Reply #2 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++ 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Problem with VertexArray declaration?
« Reply #3 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).
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Problem with VertexArray declaration?
« Reply #4 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;
« Last Edit: October 07, 2014, 06:58:40 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Problem with VertexArray declaration?
« Reply #5 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?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Problem with VertexArray declaration?
« Reply #6 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.