Search code examples
linuxvisual-c++gtkwxwidgets

wxString Printf function issues in linux


i am trying to Print some data in wxstring using printf function but its crashing in run time in LINUX but not in windows

here is my code:

wxString str1,str2;
str1 = "Elements";
str2.Printf( _U("%s"),str1);

This is working in windows but not in linux , if i change it below its working in linux also

str2.Printf( _U("%s"),str1.c_str());

why its not taking str1 as argument.

Note:This sentence i am using throughout the workspace is there any common way to do this in linux instead of changing in all places


Solution

  • The only "fix" is to upgrade to wxWidgets 3.0 where wxString::Printf() and other similar functions are (pseudo) variadic templates and so do work correctly with objects and not only raw pointers. In wxWidgets 2.8 they are variadic functions and, according to the language rules, can't work with the objects and no, there is no way around this.