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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:55:45+00:00 2026-05-16T06:55:45+00:00

I have a class where I use this to initialize a void* pointer. But

  • 0

I have a class where I use this to initialize a void* pointer. But the problem is, when I pass an instance of that class by value, the pointer will not change to the new address on the stack. So, I thought to override the copy constructor to reassign the pointer with the new address of this. But I need variables to call the super-class constructor, which I normally get by constructor-parameters, but I don’t have them in my copy constructor…

I hope I explained well…

So the question is: can I keep the procedure of the default copy-constructor, where I add the part of reassigning the pointer? Or are there better alternatives?

Thanks

Here is a some code:

class GetsCopiedByValue : public SuperClass
{
    GetsCopiedByValue(Type1 *t1, Type2 *t2, float var1, /* A lot of other things I need */) :
         SuperClass(t1, t2), var1(var1)
    {
         t1->set_GetsCopiedByValue_Address(this);  // ***
    }
}

Somewhere else:

{
    GetsCopiedByValue instance (t1, t2, 4.64, /* All the other things */);
    SomeType *t = new SomeType(instance); // <-- here, it gets copied by value,
}  // but the original "instance" goes (here) out of scope and the address 
   // I assigned (***) is not longer valid, so I have to
   // reassign the address to the new address, after copying it.
  • 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-16T06:55:46+00:00Added an answer on May 16, 2026 at 6:55 am

    Not sure if this helps, but you can actually call the superclass copy constructor in your copy constructor:

    GetsCopiedByValue(GetsCopiedByValue const& other) :
         SuperClass(other), var1(other.var1)
    {
         t1->set_GetsCopiedByValue_Address(this);
    }
    

    But I think that even if you omit this base-class constructor call, C++ will insert it for you.

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

Sidebar

Related Questions

I don't have any idea how to use this class in .net. Anyone wants
I have an AS3 class with some getVideo function. I want to use this
I have an issue regarding Sendkeys Class, as i want to use this class
i make one class file for jar. and this class have use wurfl. and
I have a base class like this: package MyClass; use vars qw/$ME list of
I have this code below. I need to use a class id instead of
.Net 3.5, using C# I have an instance of a class (A) that has
I have a static SessionFactory class that initializes an NHibernate session factory. Because this
I have a list populated with a sprite class I created. I use this
I have A WCF service that has a class that inherits System.Web.Security.RoleProvider. In 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.