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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:43:44+00:00 2026-05-30T11:43:44+00:00

I have a back up copy of data that I would like to protect

  • 0

I have a back up copy of data that I would like to protect so I made it const. I need to violate that constness on two occassions, once to store virgin data to it:

fgBlocks.CopyInto((BlkArray&)backUpCopy);

w.r.t.

result CopyInto(BlkArray &replica) const {/**/}

and again when I call RemoveAll() on it which is a non-const method:

((BlkArray)backUpCopy).RemoveAll(true);

Is the first cast (shown above, (BlkArray&)) correct? It’s the one aspect of indirection I haven’t cast to before now. Then again I’ll add another unused aspect, that of casting away constness for calling an object’s methods, which the compiler isn’t accepting as shown above.

The members are declared like this:

BlkArray fgBlocks;
const BlkArray backUpCopy;

I’m trying to extend Correa’s solution so have:

    BlkArray *pBUCopy = (BlkArray *)&backUpCopy;
    fgBlocks.CopyInto(*pBUCopy);

Only problem now is the compiler is failing due to

uninitialized member ‘MyClass::backUpCopy’ with ‘const’ type ‘const BlockArray’

  • 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-30T11:43:46+00:00Added an answer on May 30, 2026 at 11:43 am

    Be aware that if you do this and the object really is const, then modifying it after casting away the constness is undefined behaviour.

    fgBlocks.CopyInto(const_cast<BlkArray&>(backUpCopy));
    

    Same thing for the other one:

    const_cast<BlkArray&>(backUpCopy).RemoveAll(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to copy the spool data for a given Windows print job
I have several old 3.5in floppy disks that I would like to backup. My
I have a call back url, that i'm am pulling out the Lat and
Back-end: I have a model (User) that has_many of another model (ContactPreference). Front-end: An
I have a web-app with a Java back-end that uses Tomcat jdbc-pool for database
I would like to ask if anyone knows about reliability of File.Copy in a
I have an array that grabs checkbox data and posts certain information into the
I would like two threads work like this: First thread will append values to
I have an IntentService that loads up an ArrayList with data from a network
I have data comming back from web service in the form of a ObservableCollection<string>

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.