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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:38:50+00:00 2026-05-30T22:38:50+00:00

My problem statement is as below. There is a concept of domain which consists

  • 0

My problem statement is as below. There is a concept of “domain” which consists of many “subdomains”. Now, those subdomains are domains in their own right. Following is the basic method I can do the things. I can probably use an auto_ptr or something, but lets leave it for now.

class Domain
{
private:
    Domain* subdomains;
}

However, I was able to compile and run the following program which I think does the same thing and gives me what I want.

#include <iostream>
#include <vector>
#include <string>

class Domain
{
private:
    std::string name_;
public:
    std::vector<Domain> subdomains;
    Domain(std::string name) : name_(name) {};
    std::string name() {return name_;}
    void addSubDomain(std::string subDomainName);
};

void Domain::addSubDomain(std::string subDomainName)
{
    subdomain.push_back(Domain(subDomainName));
}

int main()
{
    std::cout<<"Hello, World"<<std::endl;
    Domain domain("wow");
    domain.addSubDomain("wow-child");
    std::cout<<"Domain name is "<<domain.name()<<std::endl;
    std::cout<<"Subdomain name is "<<domain.subdomain[0].name()<<std::endl;
    return 0;
}

The output which I get on running this is

$./main 
Hello, World
Domain name is wow
Subdomain name is wow-child

My question is whether there are any pitfalls that I may have missed while implementing the following thing? Right now, there is nothing I can see. If there are no pitfalls, then this is the a really good solution to my problems.

EDIT

In case this is not a solution, then is there another solution that I can use which does not involve the management of raw pointers?

  • 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-30T22:38:52+00:00Added an answer on May 30, 2026 at 10:38 pm

    This is undefined behavior because at the point you define the member, the class is not yet completely defined. At that point, std::vector<Domain> needs to be instantiated though, from the template std::vector<T> to a class std::vector<Domain> (to determine its size, among others). When that instantiation happens, the Standard requires the class to be completely defined.

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

Sidebar

Related Questions

In my SQLite statement below there is a problem with division by zero in
I have a problem when trying to execute this update statement (below) using C#
I have a problem with the SQL statement detailed below. The query returns the
Problem statement: It is necessary for me to write a code, whether which before
I have a pagination script which I have posted below, the problem is I
Below I have a nested if statement which loads a certain CSS file depending
Problem statement: Implement a plug-in system that allows the associated assemblies to be overwritten
Problem Statement: I'm creating a template for multi tiered complicated calculations in MS Excel
Here is the problem statement: Calling a setter on the object should result in
I have a problem with a continue statement in my C# Foreach loop. I

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.