0

I have this:

main.cpp

#include <vector>
#include "Bola.h"

Bola B1();
std::vector <Bola> Ball;
void addBalls();  //this function is the problem

int main()
{
    addBalls(); //Replace

    //Here is where I draw everything

    return 0;
}

void addBalls() {
    Bola nB ();
    Ball.push_back(nB);
    Ball.back().getBall().setPosition(0, 30);  //Not working
}

Bola.h

#include <SFML/Graphics.hpp>

class Bola {
    sf::Texture tBall;
public:
    Bola();
    sf::Sprite getBall();
    ~Bola() {}
private:
    sf::Sprite sBall;
};

Bola.cpp

#include "Bola.h"

Bola::Bola() {
    tBall.loadFromFile("imgs/bola.png");
    sBall.setTexture(tBall);
}
sf::Sprite Bola::getBall() {
    return sBall;
}

The vector and the function addBalls() togheter are not working. If I try to add a new ball using the function it does add a new ball but the sprite does not get rendered.

if I instead add a new ball to the vector using "the same code of the function" addBalls() in the place where I call the function now the sprite gets rendered somehow.

I cant see what´s wrong.

Thanks in advance.

  • 1
    `Bola nB ();` declares a *function*, named `nB` that take no arguments and return a `Bola` object by value. Change to plain `Bola nB;` – Some programmer dude Dec 17 '22 at 05:38
  • 1
    Read about vexing parse. – Jason Dec 17 '22 at 05:43
  • 1
    *"it does add a new ball"* -- this seems unlikely since the code you posted does not compile, so it does not do anything. When I tried compiling, I got a (relevant) warning followed by `error: no matching function for call to 'std::vector::push_back(Bola (&)())'`. – JaMiT Dec 17 '22 at 05:50

0 Answers0