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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:34+00:00 2026-05-25T19:30:34+00:00

in my object State, i’d like to have object pq. but pq needs to

  • 0

in my object State, i’d like to have object pq. but pq needs to be initialized with a parameter. is there a way to include a class that depends on a parameter into another class?

file.h

class Pq
{
  int a;
  Pq(ClassB b);
};
class State
{
  ClassB b2;
  Pq pq(b2);
  State(ClassB b3);
};

file.cc

State::State(ClassB b3) : b2(b3) {}

  • 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-25T19:30:35+00:00Added an answer on May 25, 2026 at 7:30 pm

    You can initialize it in the initializer list, just like you do with b2:

    State::State(ClassB b3) : b2(b3), pq(b2) {}
    

    Keep in mind that members are initialized in the order they are declared in the header file, not the order of the initializers in the initializer list.

    You need to remove the attempt at initialize it in the header as well:

    class Pq
    {
      int a;
      Pq(ClassB b);
    };
    class State
    {
      ClassB b2;
      Pq pq;
      State(ClassB b3);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that you have a business object whose current state implies that there
i have program like this private void do_my_method_click(object sender, RoutedEventArgs e) { //there are
Does hibernate provide a method that returns an object's state (transient, persistent, detached)?
Suppose I have a method which changes the state of an object, and fires
Good day. I know that in order to save object state in Java I
We have a project that uses an Interceptor object to tell NHibernate to do
I have a member function of an object that is typically used in an
I have problem with this method in NLog library: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state) It consume too
I have an object that is deserialized with this: public object DeSerializeObject(string filename) {
I have a method that calls another method of a mocked object with a

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.