static const error C2864

276
04 августа 2017, 01:24

Перенимаю проект бывшего рабочего в комании. Проект был разработан на GL Studio и генирирует очень много файлов сам, т.е программирования как такого, не так много. При компиляции проекта, произошла ошибка которую я никак не могу понять.

файл с ошибками:

#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 );
};

Следующие ошибки вылазию при компиляции:

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
Answer 1

Проблема в таких строках:

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

Компилятор вам прямо говорит, что таким образом можно инициализировать только статические целочисленные константы. Решения два:

1) Включите поддержку C++11. Там такие трюки прокатывают.
2) Инициализируйте все поля в конструкторах:

class ViewHub{
    //...
    const char *NAME_PANEL_FLIGHT_TEXT_BOX;
    ViewHub():
        NAME_PANEL_FLIGHT_TEXT_BOX("customTextBox")
    {}
    //...
};
READ ALSO
Есть ли аналог #include &ldquo;printBinary.h&rdquo; в С++

Есть ли аналог #include “printBinary.h” в С++

Дана программа с использованием поразрядных операторовПроблема в printBinary

383
WinAPI TCP Port Mapper

WinAPI TCP Port Mapper

Нужен исходник прокси сервера, пробрасывающего запросы от клиента (FireFox) к вышестоящему HTTP прокси и обратно

270
Как работает wifstream и getline на больших файлах? [требует правки]

Как работает wifstream и getline на больших файлах? [требует правки]

Сделал построчное чтение с файла с помощью wifstream и getlineНа маленьких файлах все хорошо

376
Многопоточность и синхронизация в C++

Многопоточность и синхронизация в C++

Добрый день всем! В ходе работы с многопоточностью в C++ у меня возникли некоторые проблемыЯ качаю некоторые данные(файлы небольшого размера)...

418