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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:04:21+00:00 2026-06-02T02:04:21+00:00

I have two different versions of the constructor for my Policy class. I can’t

  • 0

I have two different versions of the constructor for my “Policy” class. I can’t seem to pass a Policy object by reference when using one of the constructors, and I don’t understand why not.

Overloaded constructors:

Policy::Policy(int testing) { 
    initAge=160;    
    initState=1;    

    reset();        

    x[0]=4;
    x[1]=2;
    ub[0]=10;
    ub[1]=10;
    lb[0]=0;
    lb[1]=0;

}

Policy::Policy() {
    initAge=160;
    initState=1;

    reset();    

    x[FRQ]=4;
    x[BEG]=40*4;
    x[END]=75*4;
    for(int i=0; i<240; i++)
        x[2+i]=4.0;
    x[GS]=2;

    lb[0]=1;
    ub[0]=80;
    for(int i=1;i<3;i++) {
        lb[i]=160;
        ub[i]=400;
    }
    for(int i=3;i<243;i++) {
        lb[i]=1;
        ub[i]=16;
    }
    lb[243]=2;
    ub[243]=4;

} 

Here’s my code that gives the error.

void sampleMIXD(Constraints& space, Policy& p);

int main(int argc, char** argv) {

//  Policy policy(1); // Works
    Policy policy(); // Does not work

    Constraints space(2);

    sampleMIXD(space, policy);

    return 0;
}

Error message:

'../main.cpp:64: error: invalid initialization of non-const reference of type 'Policy' from a temporary of type 'Policy (*)()'
../MIXD.h:12: error: in passing argument 2 of 'void sampleMIXD(Constraints&, Policy&)'

If instead of Policy policy(); I compile with Policy policy(1);, then the compiler doesn’t complain. Please help! 🙂

  • 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-02T02:04:21+00:00Added an answer on June 2, 2026 at 2:04 am
    Policy policy(); // Does not work
    

    That’s the most vexing parse. Try

    Policy policy;
    

    Basically, the compiler treats your variant as a declaration of a function taking nothing and returning policy. It’s similar to

    int rand();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different projects and in one, I have a class that defines
I have a need to reference two different versions of the Sharepoint API dll.
My one ASP.NET web site uses two different business object class libraries. There is
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
I have two different modules that need access to a single file (One will
I have two different applications and I am using GroupLab Networking to communicate between
I have two different versions of linux/unix each running cfengine3. Is it possible to
I have php two servers with different versions of php, and am having trouble
Basically, I want a class to be able to implement two different versions of
I have two different versions (Basic and Professional) of my application. I have created

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.