I adopt the project of a former worker in the company. The project was developed on GL Studio and generates a lot of files itself, that is, programming as such, not so much. When compiling the project, an error occurred that I just can not understand.

file with errors:

#pragma once #include "aladintypes.h" #include "gls_text_box.h" #include "ProgressBar.h" // panels to forward information to #include "Oberes_Zusatzpanel.h" #include "Panel_Flug.h" // std:: headers #include <ctime> #include <cmath> #include <stdexcept> #include <string> /* * VIEW HUB * * Forwards information recieved by Drone Connection * to elements of the GUI for display. * For faster access it uses GLStudio's FindByName method only once * on initialization and stores the link in a pointer using the * method gatherLinksToDisplays(). * * throws logic_error if elements of the UI cannot be found by name * * */ class ViewHub { public: ViewHub( void ); void setLinks( disti::Oberes_ZusatzpanelClass *, disti::Panel_FlugClass *, disti::ProgressBarClass *downlinkProgressBar ); // send information to panels linked void showNotConnected( void ); void showStateResponse( est::aladin::SystemStateResponse & ); int roundToInt( double ); std::string currentTimeAsString(); std::string geoCoordToString( double coord, bool isLat ); private: // NAME Literals of the elements for display const char *NAME_UPPER_PANEL = "Oberes_Zusatzpanel_Informationsbereich_Text"; const char *NAME_PANEL_FLIGHT_TEXT_BOX = "customTextBox"; //$$ NOTE : "customTextBox" is the name of a dummy TextBox I've put //$$ on top of the original textbox derived for readability. //$$ The Original name is : "Panel_Flug_Textfeld_gross_text" // Links to the elements for display disti::GlsTextBox *m_oberesZusatzpanelTextBox = nullptr; disti::GlsTextBox *m_panelFlugTextBox = nullptr; disti::ProgressBarClass *m_downlinkProgressBar = nullptr; void writePanelFlug( est::aladin::SystemStateResponse &response ); void writeOberesZusatzpanel( est::aladin::SystemStateResponse &response ); // Converts the postition provided by the parameter in the correct // format for display in the panels std::string positionAsString( est::aladin::DynamicsState & ); // called in constructor void gatherLinksToDisplays( disti::Oberes_ZusatzpanelClass &, disti::Panel_FlugClass & ); // convert to string adding a leading zero // in case the parameter is smaller than ten // used by positionAsString std::string twoDig( int ); }; 

The following errors clash when compiling:

 error C2864: 'ViewHub::NAME_UPPER_PANEL' : only static const integral data members can be initialized within a class error C2864: 'ViewHub::NAME_PANEL_FLIGHT_TEXT_BOX' : only static const integral data members can be initialized within a class error C2864: 'ViewHub::m_oberesZusatzpanelTextBox' : only static const integral data members can be initialized within a class error C2864: 'ViewHub::m_oberesZusatzpanelTextBox' : only static const integral data members can be initialized within a class error C2864: 'ViewHub::m_downlinkProgressBar' : only static const integral data members can be initialized within a class 
  • use compiler with C ++ 11 support - Abyx
  • @Abyx how else can you solve this problem? - Insider
  • otherwise code in C ++ 03 - Abyx
  • @Insider: "generates a lot of files by yourself"? Well, and here these files, in which errors are generated files or handwritten files? Why the question is not specified? - AnT
  • @AnT because this is not known and there is nobody to ask. - Insider

1 answer 1

The problem in these lines:

 class ViewHub{ //... const char *NAME_PANEL_FLIGHT_TEXT_BOX = "customTextBox"; //... }; 

The compiler directly tells you that in this way you can only initialize static integer constants. There are two solutions:

1) Enable C ++ 11 support. There are such tricks rolled.
2) Initialize all fields in constructors:

 class ViewHub{ //... const char *NAME_PANEL_FLIGHT_TEXT_BOX; ViewHub(): NAME_PANEL_FLIGHT_TEXT_BOX("customTextBox") {} //... }; 
  • tell disti::GlsTextBox *m_oberesZusatzpanelTextBox = nullptr; how to turn the same with for example disti::GlsTextBox *m_oberesZusatzpanelTextBox = nullptr; - Insider
  • @Insider, hmm, something weird is happening there. nullptr also from C ++ 11. Your compiler may not fully support C ++ 11. Try using a later version, or rewrite the code in C ++ 03 - yrHeTaTeJlb