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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:59:37+00:00 2026-06-15T02:59:37+00:00

For example, I create a class named Circle and define it in Circle.h .

  • 0

For example, I create a class named Circle and define it in Circle.h.

class Circle {
    public:
        Circle *parent;

        Circle();
};

And in a separate Circle.cpp file under the same directory as Circle.h, I define the constructor.

Circle::Circle() {
    // creates a root circle, parent is set to itself
    *parent = ????
}

What should I fill in the ???? part? In AS3, I know you can use the this keyword to represent the instance itself when defining functions of the class. What do you use in C++?

EDIT 2012/11/29 23:56

There is another constructor:

Circle(Circle*);

Circle::Circle(Circle *cParent) {
    *parent = *cParent;
}

And a function, when called, creates a new Circle instance and set the new instance’s *parent to caller.

void addChild();

void Circle::addChild() {
    Circle child(????);
}

???? is still that mystery part. According to resources I have read, this seems to be deprecated or has become of other meanings?

  • 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-15T02:59:40+00:00Added an answer on June 15, 2026 at 2:59 am

    The keyword you’re looking for is this; it’s a pointer to the instance on which the function was invoked. In your example, you’d use it like this:

    Circle::Circle()
    {
      parent = this;
    }
    

    Note that it must be parent = this;, not *parent = this;. The latter would assign into the object parent is pointing to, which is not valid (parent has an indeterminate value). Fortunately, it wouldn’t compile, as you’d be assigning a pointer into an object.

    For cases such as this (initialising a data member inside a constructor), C++ has the initialiser syntax, which is generally preferred to assigning the members in the constructor body. The code would then look like this:

    Circle::Circle()
      : parent(this)
    {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a template class in C#, for example: public class Foo<T>
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I have a class named Person with multiple properties, for example: public class Person
UPDATE: This is the working example. First we create a class to hold weekday,
For example I now created a this tiny class: public static class FileSystemInfoComparers<T> where
I have created a separate class (let's call it class2.cs for example) and want
I have a jar file named stdlib-package , the .class files in this jar
I have class named worker , I want to create new instance of this
I have the following variable in a class named Example: private static int number;
Stumped with a OOP interface F# question. Example - when I create a class

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.