-4

Fl_Widget have next constructor:

Fl_Widget (int x, int y, int w, int h, const char *label=0L)

How can i send char* instead const char*? I just want use my char Tmp[255] variable in constructor.

Xaver
  • 991
  • 2
  • 19
  • 37

2 Answers2

3

C++ allows the implicit casting of a T* to a const T* for any type T so in your case you can just pass the parameter to the function.

Also, if you own the Fl_Widget constructor, then you should change the default value for label from 0L to nullptr, or 0 if using C++03 or earlier.

(To convert from const T* to T* requires a const_cast and can lead to undefined behaviour).

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • 1
    In more general terms `const` can always be implicitly added, but not removed without `const_cast`, which should basically never be used. – bcrist Oct 23 '14 at 11:58
0

If your ctor currently looks like this, where foo is your class:

foo::foo() : FL_Widget(13, 13, 13, 13, Tmp){
    char Tmp[255]{"blah blah blah"};
}

That's not legal. You cannot pass a parameter to a parent ctor that happens in your class's ctor, this is because the parent ctor happens before your class ctor is called.

You could instead do this: foo::foo() : FL_Widget(13, 13, 13, 13, "blah blah blah"){}

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288