-
programmerGuyLikes 0Problem Description
Hello I have a question about your menu class tutorial. I get one error saying
"No matching function for call to 'Menu::Menu(unsigned int, unsigned int)" my constructor's arguments are are MainMenu::MainMenu(int width, int height). Why am I getting this error?
-
Sonar Systems adminLikes 0
What tutorial are you following?
-
programmerGuyLikes 0
tutorial 51: Menu class in the SFML course
-
Sonar Systems adminLikes 0
Can you show us your code/
-
programmerGuyLikes 0
//Main Menu header file
#ifndef MAINMENU_H
#define MAINMENU_H
#include <SFML/Graphics.hpp>
//#include "MainMenu.cpp"
//Cyber Pong main menu
class MainMenu
{
private:
int selectedItemIndex;
sf::Font font;
static const int Max_Items = 3;
sf::Text menu[Max_Items];
public:
MainMenu(int width, int height);
~MainMenu();
void draw(sf::RenderWindow &window);
void move_up();
void move_down();};
#endif // MAINMENU_H//Main Menu.cpp
#include <iostream>
#include "MainMenu.h"//menu constructor
MainMenu::MainMenu(int width, int height)
{
if(!font.loadFromFile("fonts/arial.ttf"))
{
//Handle font error
}
//menu list
menu[0].setFont(font);
menu[0].setColor(sf::Color::Green);
menu[0].setString("Play");
//divide the width by 2 and height by the max number of items on list
menu[0].setPosition(sf::Vector2f(width/2, height/(Max_Items + 1) * 1));menu[1].setFont(font);
menu[1].setColor(sf::Color::Green);
menu[1].setString("Options");
//divide the width by 2 and height by the max number of items on list
menu[1].setPosition(sf::Vector2f(width/2, height/(Max_Items + 1) * 2));
menu[2].setFont(font);
menu[2].setColor(sf::Color::Green);
menu[2].setString("Exit");
//divide the width by 2 and height by the max number of items on list
menu[2].setPosition(sf::Vector2f(width/2, height/(Max_Items + 1) * 3));
}
//menu destructor
MainMenu::~MainMenu()
{
}//draw main menu list
void MainMenu::draw(sf::RenderWindow &window)
{
for(int i = 0; i < Max_Items; i++)
{
window.draw(menu[i]);
}
}
// In my main.cppsf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight), "Pong!");
//create menu object as type Mainmenu
MainMenu menu;
menu(window.getSize());So the gameWidth = 800 and height = 600. I get the error at menu(window.getSize());
-
Sonar Systems adminLikes 0
Where is that line I can’t see it?
Login to reply