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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:24:10+00:00 2026-06-09T02:24:10+00:00

Description: I cannot set a variable or change it while it is defined volatile

  • 0

Description:

I cannot set a variable or change it while it is defined volatile (in Main). Removing volatile solves the problem, but I need my variable to be volatile.

My tries:

Really a lot of tries out there. Overloading operator=, making new operator= volatile, making new volatile method. Nothing actually worked so far.

My main:

int main() {
    volatile PlaceParentConversion s(10.0); // remove volatile = no errors
    std::cout << s.mX << std::endl;
    s = PlaceParentConversion::IDENTITY_CONVERSION;
    std::cout << s.mX << std::endl;
    return 0;
}

My class:

class PlaceParentConversion {
public: //all public, easier to check
    const static PlaceParentConversion IDENTITY_CONVERSION;
    double mX;
    PlaceParentConversion(const double x);
    PlaceParentConversion(const PlaceParentConversion& other);
};

const PlaceParentConversion PlaceParentConversion::IDENTITY_CONVERSION(0);

PlaceParentConversion::PlaceParentConversion(const double x) : mX(x) {}
PlaceParentConversion::PlaceParentConversion(const PlaceParentConversion& other) : mX(other.mX) {}

Error:

‘volatile PlaceParentConversion’ as ‘this’ argument of ‘PlaceParentConversion& PlaceParentConversion::operator=(const PlaceParentConversion&)’ discards qualifiers [-fpermissive] 
  • 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-09T02:24:11+00:00Added an answer on June 9, 2026 at 2:24 am

    Define a volatile assignment operator:

    Foo volatile & operator=(Foo const & rhs) volatile
    {
        // ...
        return *this;
    }
    

    (I’ve shortened your class name for readability.)


    Here’s a more complete example:

    struct Foo
    {
        Foo() { }
        Foo(Foo const volatile &) { }
        Foo volatile & operator=(Foo const &) volatile
        { return *this; }
    };
    
    int main()
    {
        volatile Foo x;
        Foo y;
        static_cast<Foo>(x = y);
    }
    

    The static cast in the final line makes GCC not issue a warning that no access is happening to the volatile object which is the result of the evaluation of the assignment expression: the standard says that in a void context there is no lvalue-to-rvalue conversion and thus no access. We make the conversion explicit.

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

Sidebar

Related Questions

Description: I have a problem regarding DataGridView . I need to show a Client_Name
SHORT DESCRIPTION OF PROBLEM: I want to set the text of a searchbar without
Perhaps there is an easy solution for my problem but I simply cannot seem
I've already seen this post: Changing the size of Html.TextBox But I cannot change
In the ASP.net, I try to set a variable value to hidden field, but
Problem description: Read an xml file, traverse to a particular node (element), if it
I cannot understand why the date is never set in the title - it's
I need to do following tasks: List the interfaces Set/remove/list IPv6 address Add/remove routing
i am having no problem at all compiling/debugging my web app, but when i
public class RegisterSubscription { public string ID { get; set; } public string Description

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.