A
A
Anton Boyarshinov2016-02-20 21:48:41
C++ / C#
Anton Boyarshinov, 2016-02-20 21:48:41

C++, no default constructor found, what's the problem?

There is a code

class mainWindow : public Fl_Window {
public:
  mainWindow(int w, int h, int x, int y,const string& t)
  {
    Fl_Window(x,y,w,h,t.c_str());
  }
  ~mainWindow();
  Fl_Button *start1 = new Fl_Button(180, 140, 40, 20, "Start");
};

And it keeps throwing a compilation error.
Ошибка	1	error C2512: Fl_Window: нет подходящего конструктора по умолчанию

In a similar redefinition it works, for me it doesn't.
The Fl_Window constructor looks like this:
Fl_Window(int x, int y, int w, int h, const char* title = 0);
Fl_Window(int w, int h, const char* title= 0);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MiiNiPaa, 2016-02-20
@MiiNiPaa

Fl_Window(x,y,w,h,t.c_str());Here you create a temporary local object of type Fl_Window. Is this what you need?
If you want to initialize the base class, do it in the initialization list:

mainWindow(int w, int h, int x, int y,const string& t) : Fl_Window(x,y,w,h,t.c_str())
  {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question