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 8958009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:07:31+00:00 2026-06-15T15:07:31+00:00

I am experiencing some strange behavior with Visual Studio 2010 and C++. I have

  • 0

I am experiencing some strange behavior with Visual Studio 2010 and C++.
I have a header file in which I declare some global constants

#ifndef CONSTANTS_H
#define CONSTANTS_H

#define WIN32_LEAN_AND_MEAN

// Macros...
#define SAFE_RELEASE(ptr) { if (ptr) { ptr->Release(); ptr = NULL } }
#define SAFE_DELETE(ptr) { if (ptr) { delete ptr; ptr = NULL; } }

// Constants...
const char* CLASS_NAME = "WinMain";
const char GAME_TITLE[] = "DirectX Window";

const int GAME_WIDTH = 640;
const int GAME_HEIGHT = 480;

#endif

My problem comes in with the following line:

const char* CLASS_NAME = "WinMain";

When it’s like this, and I build my solution I get the following 2 errors:

error LNK1169: one or more multiply defined symbols found, and

error LNK2005: "char const * const CLASS_NAME" (?CLASS_NAME@@3PBDB) already defined in graphics.obj

Now is strange since a ran a ‘find in files’ and I definitely do not declare it somewhere else ie no duplicate declarations.

Should I change it to:

const char* const CLASS_NAME = "WinMain";

OR

const char CLASS_NAME[] = "WinMain";

It compiles just fine! But as far as I know char* x is equivalent to char x[], and the fact that I’m enforcing ‘const-ness’ on both the pointer and the pointed-to value should make no difference…. or does it?

I’m a bit new to C++ development on the Windows platform, so any help will be greatly appreciated!

  • 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-06-15T15:07:32+00:00Added an answer on June 15, 2026 at 3:07 pm

    You mistake is that you did not declare your constants as constants. In C++ syntax (as well as in C) in order to declare a constant pointer you have to do this

    const char* const CLASS_NAME = "WinMain";
    

    Note that your GAME_TITLE, GAME_WIDTH and GAME_HEIGHT are correctly declared as constants, which is why they give you no trouble. Only the CLASS_NAME is declared incorrectly, i.e. as non-constant.

    Constants in C++ have internal linkage by default, which is why you can define them in header files without violating the One Definition Rule.

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

Sidebar

Related Questions

I'm experiencing some strange behavior for which I can't find any documented knowledge. Here's
I am experiencing some strange behavior with SQL Server CE 3.5 SP2. I have
I am experiencing some strange behavior in my datagrid when I have a second
I am experiencing some very strange behavior when including a php file. I need
I'm currently experiencing some problems with my server. I have a pool which is
I am experiencing some problem on UTF-8 Encoding. I have a CSV file and
I'm experiencing some strange behavior in Eclipse. I'm trying to export my Android application,
I'm experiencing some strange behavior when using tableviews in iOS6. I see they've added
I am experiencing some strange behavior with OSQL, and would appreciate any help. I
I am experiencing some strange behaviour and I really don't have test date/ environments,

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.