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

Author Topic: Passing arguments in classes - Error: no function to call  (Read 1076 times)

0 Members and 1 Guest are viewing this topic.

JasonMcG

  • Newbie
  • *
  • Posts: 10
    • View Profile
Passing arguments in classes - Error: no function to call
« on: September 19, 2017, 10:55:10 am »
I have a class called Rock and I'm passing in my player class.

Code: [Select]
Rock::Rock(Player& player){
    _rock.setTexture(_rockTexture);
    _rock.setOrigin(650,500);
    _rock.setPosition(X, Y); 

   _player = &player;
}

In my Game glass, which is the game engine, I get an error

Code: [Select]
Game::Game():
    _window(sf::VideoMode(WIDTH, HEIGHT), "ROCK"){

}

Error: no function to call Rock::Rock()

I assume this is because rock is taking a parameter.
But in Game:Game, how am I supposed to define something here to satisfy this error?
I tried making the Rock object in Game a pointer by that crashes the program.

If I had to pass any argument into the Rock constructor, how do I satisfy it in the Game class?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Passing arguments in classes - Error: no function to call
« Reply #1 on: September 19, 2017, 11:13:37 am »
The same way you pass the arguments to the window constructor

Game::Game():
    _window(sf::VideoMode(WIDTH, HEIGHT), "ROCK"),
    _rock(player) // I assume that your Rock instance is named "_rock", and that you have a Player instance named "player"
{
}

PS: this is the SFML forum, so we try to focus on SFML specific problems; there are better places for general C++ questions
Laurent Gomila - SFML developer

 

anything