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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:05:13+00:00 2026-06-09T05:05:13+00:00

Building on my question here: C++ cannot establish handle reference to 'parent' object —

  • 0

Building on my question here: C++ cannot establish handle reference to 'parent' object — circular includes or undefined type errors I’d like to create a class (called Node) that has two generic typed members, a generic pointer to a type-to-be-determined parent object and a vector of generic pointers to the elements of a set of type-to-be-determined child objects. Objects which are to exist in a two-way tree structure will inherit from Node and can populate its parent and children members if necessary as that data becomes available. Here is what I have so far to that end for Node.h:

#include <vector>

#ifndef NODE_H_
#define NODE_H_

template<typename T> class parent{};
template<typename T2> class child{};
class Node{

private:
parent<T>* parent_ptr;
vector<child<T2>>* children_ptr;

public:
 //some accessor methods will go here to get and set the parent and children
};
#endif /*NODE_H_*/

obviously this is not the correct way to use templates in C++ as I am getting error C2065 “‘T’ is an undeclared identifier” and C4430 “missing type specifier – int assumed” errors. I’ve found some useful documentation on creating template classes and functions here: http://www.cprogramming.com/tutorial/templates.html but neither that tutorial nor any other docs I could find seem to cover using templates to declare generic class members inside a non-template class; I’m fairly sure that this (or something similar) is what I need to do for my use-case, so what is the proper way to declare and use generic member variables in a standard C++ class?

  • 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-09T05:05:16+00:00Added an answer on June 9, 2026 at 5:05 am

    You should definitely spend some time understanding how templates work and start with something simple. It took years for me to be able to create complicated template objects without a lot of compiler error debugging and even longer how to design code structures that minimize that complexity.

    But here’s what I think you intended. You had too much information in your templating and just needed to drop the typenames to Parent and Child (or T and T2 if you want — though those names are confusing).

    #include <vector>
    
    #ifndef NODE_H_
    #define NODE_H_
    
    template<typename Parent, typename Child>
    class Node{
    
    private:
    Parent* parent_ptr;
    std::vector<Child*> children_ptr;
    
    public:
     //some accessor methods will go here to get and set the parent and children
    };
    #endif /*NODE_H_*/
    

    Also as a side note, you may want a parent ownership situation, where parents own their children and free their memory when they are finished (if each child is owned by exactly 1 parent). In which case the vector would become:

    vector<Child> children;
    

    Otherwise you’ll need to create a nice structure for how to delete the tree. An alternative is to use smart pointers which delete themselves once they are unused (good for abstract structures that are difficult to track). See Boost Smart Pointers or equivalent from later revisions of C++, though they need special care for circular references.

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

Sidebar

Related Questions

I'm building a custom autoloader based on Zend Framework's autoloading (related question here ).
When building my C++ program, I'm getting the error message undefined reference to 'vtable...
Newbie question here! I'm building a simple application that allows users to create and
Its probably a very subjective question, but here it goes....We're building a website that
Reference is made to prior question here: How do I use jquery validate remote
Here is a weird question. I am building an array of objects manually, like
I asked a question about building custom Thread Safe Generic List now I am
I have a question regarding building GUI applications. I feel like the title of
Looking at the general trend of comments in my question about Building an Aircraft
noob question: I'm building a checkout system for an online commerce site. I'm getting

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.