Extern with Class Objects

I get the error "error C2512: 'Button' : no appropriate default constructor available." I've tried it with extern Button buttonStart(parameters), extern class Button ButtonStart(parameters).. Everything you could think of I've changed it. Anyone know why it's like this? (Error is on line 32)

Main.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef MENU_H
#define MENU_H

#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>

#include "Button.h"

class Menu
{
private:
	Menu();
	~Menu();
public:
	sf::Texture ButtonTxtrStart;

	void Load();
	void MainMenu(sf::RenderWindow& Window);

	

};

extern Button buttonStart;

#endif 


Menu.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>

#include "Menu.h"
#include "Button.h"

Button buttonStart;

Menu::Menu()
{

}

Menu::~Menu()
{

}

void Menu::Load()
{
	ButtonTxtrStart.loadFromFile("Assets//ButtonTxtrStart.png");

	Button buttonStart(1024/2, 768/2, ButtonTxtrStart);


}

void Menu::MainMenu(sf::RenderWindow& Window)
{


	Window.draw(buttonStart.ButtonSpr);

}

Oh, and the Button parameters are Button(int x, int y, sf::Texture& SpriteTxtr)
You haven't show us the declaration for your Button class.

At line 7, you're defining a button called buttonStart. Since there are no arguments, Button's default constructor will be called, therefore Button must have a default constructor.
Topic archived. No new replies allowed.