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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:13:48+00:00 2026-06-02T07:13:48+00:00

For my homework assignment, I have to create a linked list and it must

  • 0

For my homework assignment, I have to create a linked list and it must be a template class. The assignment calls for one template class called List and another nested template class called Link.

The methods should be defined outside of the class definition.

I created a simple version of the assignment first and it’s working, but I feel there is an error in my design.

#include <iostream>
using namespace std;

template <class T1>
class A
{
public:
  template <class T2>
  class B;

  T1    _a;
};

template <class T1>
template <class T2>
class A<T1>::B
{
public:
  T2 _b;
};

int main()
{
  A<int> a;
  a._a = 5;

  A<int>::B<int> b;
  b._b = 10;

  cout << a._a << " " << b._b << "\n";


  return 0;
}

My main question is, since the nested class will be of the same type, as you can see from the statement A<int>::B<int> b;, is there a way to have class B automatically be of the same type as A? Does my question even make sense? In other words, can I do A<int>::B b; and b automatically the same type as A? There will never be a situation where I would have A<double>::B<int>; for example.

  • 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-02T07:13:51+00:00Added an answer on June 2, 2026 at 7:13 am

    Yes, just make B not a template. T1 in B‘s definition still refers to the template argument of A.

    template <class T1>
    class A
    {
    public:
      class B;
    
      T1    _a;
    }
    

    Now, instead of A<int>::B<int>, it’s simply A<int>::B.

    List<int>::Link<double> wouldn’t make sense anyway, so there’s no point in it being a template.

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

Sidebar

Related Questions

For my homework assignment for my C++ class, I have to create a Linked
I have the following assignment for homework. Requirements Design a class called TokenGiver with
Greetings I've been working on a homework in which I must create a linked
I need little help on a homework assignment. I have to create a 10
I have been given a homework assignment where I need to create a captcha
Note: This is a homework assignment. I have two classes, one inherits from the
I have a linked list question that stems from this homework prompt I am
I am currently working on a homework assignment where I have to create a
I've got a homework assignment where I have a base class Package, and two
Have a homework assignment in which I'm supposed to create a vector of pointers

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.