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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:46:58+00:00 2026-06-12T04:46:58+00:00

I’m working on an MFC application, I want to make a global string variable

  • 0

I’m working on an MFC application, I want to make a global string variable to be shared between all the actions in the application, I made a static string variable inside a header file but when I attempt to access it inside one of the actions this compiler error arises:

error C3381: 'comp' : assembly access specifiers are only available in code compiled with a /clr option

This is my header file, inside it is the class:

//Shared_Variable.h
class comp
{ 
comp() { } // private default constructor
public:
    static CString myValue;
};

and I used it inside one of my actions as follows:

void CCalculatorDlg::OnBnClickedButton1()
{
comp::myValue="1"; ----->accessing the static member of my class
LPCTSTR btn_title=_T("1");
SetDlgItemText(IDC_EDIT1,btn_title ); 

}
  • 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-12T04:47:00+00:00Added an answer on June 12, 2026 at 4:47 am

    A few possibilities at first glance;

    • Did you #include “Shared_Variable.h” in your action code file?
    • Is comp declared in a namespace, and do you need to qualify down to it, or add a using declaration into the namespace?
    • What is CString? I don’t recognize this as a C++ type.
    • If the error message is valid, it’s suggesting that it’s trying to interpret ‘comp’ as a reserved word. Have you enabled a VC specific compiler extension (or failed to disable one that competes with that keyword)? Or, have you forgotten a semicolon or other expression terminator above the class definition?

    Additionally, declaring a static member inside a class within a header like that requires that you have a single .cpp file that defines the single instance of that member. So you can declare it in the header as:

    static CString myValue;
    

    but you have to do this within Shared_Variable.cpp:

    CString comp::myValue;
    

    Without this, you’ve defined a static variable but not told C++ where to stick it in memory. Since header files are pulled in as dependencies to (potentially) multiple CPP files, you always have to make sure that anything static is pinned to exactly one CPP file, which is what the above code snippet is about.

    An alternate way to make a simple static variable is to declare in your header file:

    extern CString myValue;
    

    and in the corresponding CPP file (any CPP file, really, it doesn’t technically even have to include the header file, although it’s a good idea):

    CString myValue;
    

    Does any of that help?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.