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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:47:27+00:00 2026-06-07T23:47:27+00:00

I have a class that that where I implemented my own constructor, destructor, copy

  • 0

I have a class that that where I implemented my own constructor, destructor, copy constructor
and copy assignment operator.

The class has a core set of members that I have in all of the the above and a set of “state variables” that I added as helpers for some of the methods.

These state variables are never (just because I didn’t bother doing it) initialized in the constructor but are initialized before being used.

As such the copy constructor and copy assignment do nothing with them. They just copy the members that I explicitly want.

  • Can this be a problem?
  • What happens to members that aren’t explicitly copied (btw, no pointers in these members)?
    • they are also not initialized in the constructor
  • Can this lead to any “hidden” problems?

Cheers
André

  • 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-07T23:47:28+00:00Added an answer on June 7, 2026 at 11:47 pm

    If those variables are part of the state of the object, then they should be copied. If the variables are not part of the state of the object, they should not be members. A variable is part of the state of the object if the outcome of any function in the interface depends on the value of that variable before the operation starts.

    There are few exceptions to the general rule above, in particular there are a few member variables that do not take part on the state of the object (they are usually marked as mutable) as synchronization mechanisms or caches for results from complex operations.

    Going back to your problem, from the description it seems that you might be using those members only as a communication mechanism between different member functions. One function in the interface sets the values and then calls other functions that read/modify them. If that is the case, consider passing the variables to the functions as arguments. By using members you are effectively hiding the dependency of the functions towards those values, and at the same time adding a dependency to the class.

    This will be much worse if any of the functions in the interface access those members, in which case after the assignment (or copy construction) the source and destination will behave differently, which breaks the assumption that after copy-initialization/assignment the source and destination objects are equivalent.

    Basically, from a practical point of view, if those members are not part of the state of the object, you might get away with your current approach, but I would really reconsider the design. If they do take part in the state of the object, you should not by any means avoid copying them.

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

Sidebar

Related Questions

I have a Class ReceiveFaxPrintHelper in c# that i implemented as Sealed. I have
I have implemented a LoginAccess class that prompts the user to enter their active
Consider the code below (which has been simplified). I have a service class that
I have a class, MyThread which implements Callable <String>. The class has a constructor
I'm trying to implement my own progress bar. I have a constructor, that inits
I have a class that implements the IDisposable interface. I am using a webclient
I have a class that implements properties in a specific way, to handle some
I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public
I have a class that implements InvocationHandler as below: public class MyProxyClass implements InvocationHandler
When I have a class that implements INotifyPropertyChanged, is it ok to expose the

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.