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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:19:21+00:00 2026-05-23T21:19:21+00:00

I have a class which takes two arguments on it’s constructor, an int and

  • 0

I have a class which takes two arguments on it’s constructor, an int and a void(*)(void) so normally when I need to call it I do it like this:

obj_child (int_value, pointer_to_foo);

Now what I want is to instantiate the obj_child with constant arguments, within another class.

So I tried:

class obj_parent
{

    private:

        obj_child child_instantiation (int_value, pointer_to_foo);

};

but this seems to give me two compiler errors on the line I declare child_instantiation so I guess the arguments can’t be passed there but somewhere else.

Mind you child_instantiations are supposed to have the same arguments for all obj_parent instantiations, so they shouldn’t be passed as obj_parent constructor arguments.

Declaring the class pointer and then creating a new one on the heap compiles, but I don’t want to do it that way and I don’t know if it works (my debugger can’t watch the reference so it’s very hard to monitor it’s values).

class obj_parent
    {

        private:

            obj_child *child_instantiation;

    };

obj_parent::
obj_parent (void)
{

    child_instantiation = new obj_child child_instantiation (int_value, pointer_to_foo);


}

Thanks!

(Please don’t mind the semantics, child – parent has nothing to do with inheritance, just couldn’t think better names right now)

  • 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-23T21:19:22+00:00Added an answer on May 23, 2026 at 9:19 pm

    You have to initialize the object in the constructor of the class.

    obj_parent() : child_instantiation (int_value, pointer_to_foo) {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which constructor takes a Jakarta enums . I'm trying to
I have a class which is marked with a custom attribute, like this: public
I have a class which looks something like this: public class Test { private
I have a class with two constructors, one that takes no arguments and one
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a class, let's call MyClass. In this class, I have a TreeView
I have a class which I'm serialising to send over a unix socket and
I have a class which implements UserControl. In .NET 2005, a Dispose method is
I have a class which inherits from QTreeWidgetItem and I intercept the click event.
I have a class which is not thread safe: class Foo { /* Abstract

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.