Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:27:10+00:00 2026-05-24T09:27:10+00:00

I have a header called filepaths.h which defines a number of static variables: #ifndef

  • 0

I have a header called filepaths.h which defines a number of static variables:

#ifndef FILEPATHS_H
#define FILEPATHS_H

class FilePaths {

public:

    static QString dataFolder();
    static QString profileFolder();

private:

    static QString dataFolder_;
    static QString profileFolder_;

};

}
#endif // FILEPATHS_H

And I have an associated filepaths.cpp which initially looked like this:

#include "FilePaths.h"

QString FilePaths::dataFolder() {
    return dataFolder_;
}

QString FilePaths::profileFolder() {
    return profileFolder_;
}

However that didn’t work – I got an “unresolved symbol error” linker error on all the static variables. So I’ve added these variables to the C++ file in this way:

#include "FilePaths.h"

QString FilePaths::dataFolder_ = "";
QString FilePaths::profileFolder_ = "";

QString FilePaths::dataFolder() {
    return dataFolder_;
}

QString FilePaths::profileFolder() {
    return profileFolder_;
}

And this works, however I don’t understand why.

Why do these static variables need to be defined twice? Or maybe I’m not defining them but initializing them? But still why does it need to be done? Or should I write my class differently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:27:11+00:00Added an answer on May 24, 2026 at 9:27 am

    One is a definition, the other is a declaration. The difference is that declarations can appear multiple times, and for variables not in a class, maybe never at all, whereas definitions can appear once and only once.

    The reasons for needing separate declarations and definitions is archaic history, the kind of thing where it basically doesn’t have to be that way at all but it is that way so that C++ is compatible with C, which was designed to be compiled in the 1970s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created UITableCellView class called NoteCell . The header defines the following: #import
I have a C header file like this: #ifndef RENDERER_H #define RENDERER_H static int
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
I have a class header file called Grid.h that contains the following 2 private
I have a static 2D array called Status.Data[][] and a Column header called Status.Columns[]
I have lists inside a div called header which I want to expand the
I have one class, called A, and it has it's own header file. Then
I have a template matrix class class defined in a header called Matrix.h. Certain
I have written a class which outputs content type information as a header, however
I have the following header file: #ifndef DATABASE_H #define DATABASE_H #include <vector> #include <iostream>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.