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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:58:55+00:00 2026-05-14T02:58:55+00:00

I have a such syntax in program /* The Object1 is allowed to be

  • 0

I have a such syntax in program

/* The Object1 is allowed to be changed */
class Object1 : BaseClass {
    BaseClass *link;
    int i;
    public: 
    Object1(int a){i=a;}
    Object1(int a, Object1 /*place1*/ o) {i=a; link= &o;}
};

int main(){
/* The initialization syntax must be preserved. No any new(), no other local objects b,c */
    Object1 a(1, /*place2*/ Object1(2));
    ...
}

What do I need in place1? I want to save a link (pointer) to the second object in the first object. Should I use in place1 reference “&”?

What type will have “Object1(2)” in place2? Is it a constructor of the anonymous object? Will it have a “auto” storage type?

Thanks

UPDATE:

In the place2, the syntax is fixed and I really must support creating of “chain”, like

    Object1 a(1, Object1(2, Object1(6, Object1(999753))));

I can’t add any symbol in the definiton of a.

UPDATE2:
for place1: Object1(int a, Object1 &o) {i=a; link= &o;} and Object1 a(1, Object1(2)); in place2 I have a compile error (g++):

main.cpp||In function `int main()':|
main.cpp|19|error: no matching function for call to `Object1::Object1(int, Object1)'|
main.cpp|9|note: candidates are: Object1::Object1(const Object1&)|
main.cpp|14|note:                 Object1::Object1(int, Object1&)|
main.cpp|13|note:                 Object1::Object1(int)|
  • 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-14T02:58:55+00:00Added an answer on May 14, 2026 at 2:58 am

    In “place1”, you need a reference. Object1 isn’t fully defined, so you can’t take it by value. That said, you wouldn’t want to pass by value; when you take the address of it, you’d be getting the address of the copy, not the actual object.

    Since you only want a pointer to a BaseClass, it might make more sense to only place that restriction on the parameter. (Of course, if you really need an Object1, reflect that in the type of link: Object1* link;).

    Also consider using an initialization list:

    Object1(int a) : i(a), link(0) /* <- important! */ { }
    Object1(int a, BaseClass& o) : i(a), link(&o) { }
    

    Always use an initialize list.

    “place2” creates an unnamed instance of Object1 using a constructor. It has no storage(?) auto storage, and dies at the end of the expression.

    That is, once you’ve hit the semicolon in Object1 a(1, /*place2*/ Object1(2));, it ceases to exist and you have a pointer to an non-existent object! This results in undefined behavior.

    Give it a lifetime beyond the expression:

    Object1 x(2);    
    Object1 a(1, x);
    

    Always make sure that when you refer an object, it will live the entire time you refer to it.


    Your new compile error is because you can’t have a reference to a temporary variable. You can have one with a const-reference, though. The thing is, your pointer needs to point to a const BaseClass now, which may dampen what you want.

    Again, your design needs reworking, unfortunately.

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

Sidebar

Related Questions

I have such a class: public class Cycle { public List<int> Edges { get;
I have such html and css. <div class=selected> <div class=text>First</div> <div class=arrow>&nbsp;</div> </div> .selected
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
I have such a link in JSP page with encoding big5 http://hello/world?name=婀ㄉ And when
I have seen a syntax such as the following before: var mynum = new
I have a class: public class MyClass<T> { public string TestProperty { get; set;
I have such terrible models: class ParentalRelation < ActiveRecord::Base belongs_to :parent belongs_to :student belongs_to
Assuming i have a helper such as: @helper AddErrorSpan(string error) { <span class=error>@error</span> }
I have some class around this code, let call it ToolbarButton TBBUTTON tbbutton; ZeroMemory(&tbbutton,
I have such a problem. I'm using EF1 with VS2008 SP1 & MySQL with

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.