@Ferbines

В чём может быть ошибка?

Вот у меня есть код, вроде как рабочий, но в конце что-то пошло не так.

#include <iostream>

class Button{
private:
    unsigned width; 
    unsigned height;

public:

    Button(): width(0), height(0){};

    Button(unsigned _width, unsigned _height): 
        width(_width), height(_height){};

    unsigned getWidth(){ return width; };

    unsigned getHeight(){ return height; };

    void setWidth(unsigned _width){ width = _width; };

    void setHeight(unsigned _height){ height = _height; }; 

};

class Window{
protected:
    Button button;

    int x;
    int y;

public:

    Window(){
        x = y = 0;
    }

    Window(int _x, int _y, Button _button):
        x(_x), y(_y), button(_button){};
    
    ~Window(){
        x = 0;
        y = 0;
    }

};

class Menu: public Window{
private:
    char *title;

public:
    Menu() = default;

    Menu(char* _title, int _x, int _y, Button _button):
        title(_title), Window(_x, _y, _button){
            std::cout << "Menu has been created." << std::endl;
        };
    
    ~Menu(){
        title = NULL;
        std::cout << "Menu has been deleted." << std::endl;
    }

    friend std::ostream& operator<<(std::ostream& os, Menu& menu){
        os << "Button \"" << menu.title << "\" on (" << menu.x << "," << menu.y << ") with size " << menu.button.getWidth() << "x" << menu.button.getHeight() << ".";
        return os;  
    } 
    
};


int main(){

    Button button(10, 10);

    Menu menu("A main menu", 5, 5, button);

    std::cout << menu << std::endl;

    return 0;

}

Вот ошибка:

Error (active)	E0289	no instance of constructor "Menu::Menu" matches the argument lis  argument types are: (const char [12], int, int, Button)

Это мне выдаёт в Menu menu("A main menu", 5, 5, button);.
  • Вопрос задан
  • 108 просмотров
Решения вопроса 1
@Ferbines Автор вопроса
Уже пофиксил
const char *title;

Menu( const char* _title, int _x, int _y, Button _button):
    Window(_x, _y, _button), title(_title) {
        std::cout << "Menu has been created." << std::endl;
    };
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы