Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] problem using static pointers
QtWS25 Last Chance

[SOLVED] problem using static pointers

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 3 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fluca1978
    wrote on last edited by
    #1

    Hi all,
    I'm sure I'm missing something really stupid, but I cannot see what. I've got a class that defines the following:

    @
    class MainWindow{
    //....
    public:
    static QString* const SETTINGS_MAIN_ORGANIZATION;
    static QString* const SETTINGS_MAIN_NAME;
    }

    QString* const SETTINGS_MAIN_ORGANIZATION = new QString( "ABC" );
    QString* const SETTINGS_MAIN_NAME = new QString( "DEF" );

    @

    and I access the values stored in the static fields as:

    @
    *MainWindow::SETTINGS_MAIN_NAME
    @

    but compiling the application I got an error:

    @undefined reference to `MainWindow::SETTINGS_MAIN_NAME'@

    What am I doing wrong? My aim is to declare a static const value that must be used as a default value, so if there is a smarter way to do it (without using a #define) please let me know.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      @class MainWindow{
      //....
      public:
      static QString* const SETTINGS_MAIN_ORGANIZATION;
      static QString* const SETTINGS_MAIN_NAME;
      }

      QString* const MainWindow::SETTINGS_MAIN_ORGANIZATION = new QString( "ABC" );
      QString* const MainWindow::SETTINGS_MAIN_NAME = new QString( "DEF" );@

      --
      Vasiliy

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fluca1978
        wrote on last edited by
        #3

        Ops..what a stupid error! Thanks!

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          If the strings are static and const, why use pointers?

          @class MainWindow{
          //....
          public:
          static QString const SETTINGS_MAIN_ORGANIZATION;
          static QString const SETTINGS_MAIN_NAME;
          }

          QString const MainWindow::SETTINGS_MAIN_ORGANIZATION = QString( "ABC" );
          QString const MainWindow::SETTINGS_MAIN_NAME = QString( "DEF" );@

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            Absolutely right!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved