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

  • Home
  • SEARCH
  • 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 7664045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:12:13+00:00 2026-05-31T14:12:13+00:00

I ran into such problem: I have one header file: //first variant: #ifndef LIBRARIES_H

  • 0

I ran into such problem:

I have one header file:

//first variant:  
#ifndef LIBRARIES_H
#define LIBRARIES_H
 const char a='4';    
 #endif // LIBRARIES_H

I include it in few .cpp files.
Everything works perfect.

But suddenly, if I declare a pointer:

//second variant:
#ifndef LIBRARIES_H
  #define LIBRARIES_H
 const char *a="asdfgh";
 #endif // LIBRARIES_H

please, notice,I DECLARE ONLY ONE OF THEM(of variants).
I DECLARE a only once(I tried to change name for sadfgh or asdfg).

When I try second variant, I delete first and vise versa.

If I declare a pointer to the string I will get error “multiple inclusion of variable”.
I compile it using qt. I deleted and recompiled project a few times already.
enter image description here

Of course, I can define it in main() function, but I wonder, what is a reason of this problem? Why cannot I declare pointer in header file and afterwards to include it in few source code files?

  • 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-31T14:12:15+00:00Added an answer on May 31, 2026 at 2:12 pm
    const char a='4';
    

    means

    char const a = '4';
    

    which you can read backwards as “4 is the initial value for a which is a constant char”.

    Since this a is constant, it has internal linkage (i.e. it is not exposed to other translation units).

    On the other hand,

    const char *a="asdfgh";
    

    means

    char const * a = "asdfgh";
    

    which you can read backwards as “”asdfgh” is an array used to initialize a which as a pointer to a constant char”.

    In this case a itself is not const, and so does not get internal linkage by default: it has external linkage.

    When you include your header in two or more translation units, you therefore get two or more global and distinct objects called a, which violates the One Definition Rule of C++ (it’s often referred to as just the ODR).

    One cure is to make a itself const,

    char const * const a = "asdfgh";
    

    Now try to read that backwards, to make sense of it.

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

Sidebar

Related Questions

I ran into the problem that my primary key sequence is not in sync
Let me define the problem first and why a messagequeue has been chosen. I
I am currently developing a custom WordPress theme and ran into a problem. I
I'm new to anonymous classes, and today I think I ran into the first
I ran into a very weird problem today. Long story short, my function returns
I ran into the problem that two drives connected at nearly the same time
I've ran into a design issue; in a project, i have three tables: League,
I'm writing a C parser using PLY, and recently ran into a problem. This
I ran into a bug I have trouble explaining. Now that I found the
I'm currently working on a medium-sized web project, and I've ran into a problem.

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.