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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:29:08+00:00 2026-05-15T19:29:08+00:00

Background : I am working on a framework that generates C++ code based on

  • 0

Background: I am working on a framework that generates C++ code based on an existing Java class model. For this reason I cannot change the circular dependency mentioned below.

Given:

  • A Parent-Child class relationship
  • Parent contains a list of Children
  • Users must be able to look up the list element type at run-time

I’ve modeled this in the following testcase:

Main.cpp

#include "Parent.h"

#include <iostream>
using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
    Parent parent;
    cout << Parent::getType() << endl;
    cout << parent.getChildren().getType() << endl;
    return 0;
}

Parent.h

#ifndef PARENT_H
#define PARENT_H

#include <string>

#include "Array.h"
class Child;

class Parent
{
public:
    Array<Child> getChildren()
    {
        return Array<Child>();
    }

    static std::string getType()
    {
        return "parent";
    }
};

#endif

Child.h

#ifndef CHILD_H
#define CHILD_H

#include "Parent.h"

class Child: public Parent
{
};

#endif

Array.h

template <typename ElementType>
class Array
{
public:
    static std::string getType()
    {
        return ElementType::getType();
    }
};
  1. When I compile the above code I get:
    error C2027: use of undefined type 'Child' at return ElementType::getType();

  2. If I try #include "Child.h" instead of the forward declaration I get:
    error C2504: 'Parent' : base class undefined at class Child: public Parent

  3. If I try Array<Child*> instead of Array<Child> I get:
    error C2825: 'ElementType': must be a class or namespace when followed by '::' at return ElementType::getType();

The circular dependency comes about because:

  1. Child.h needs to know about class Parent
  2. Parent.h needs to know about class Array
  3. Array.h needs to know about class Child

Any ideas?

  • 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-15T19:29:08+00:00Added an answer on May 15, 2026 at 7:29 pm

    The error is due to the Child class not being present when the template is instantiated.

    Add the following either to Main or at the end of Parent.h:

    #include "Child.h"
    

    This compiles fine with both g++ 4 and VS 2010.

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

Sidebar

Related Questions

I read this post but I can't get it working: Change Background Color... I
Background I am working on a browser-based UI that needs to fill the entire
BACKGROUND: I am working with large geometries that will be meshed or broken down
Background: I'm working on a project that's starting out with a large SQL dump
Long-Winded Background I'm working on parallelising some code for cardiac electrophysiology simulations. Since users
Ok, I need help. This is my first question here. Background: I am working
Background We have a WinForms application with Entity Framework 4.2 code-first / FluentAPI using
A little background: We're building a library/framework for working with scientific models. We have
I come from a Codeigniter MVC background that we've been working with for some
A little background I'm working on an .net application that's uses plugins heavily, the

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.