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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:08:49+00:00 2026-06-07T02:08:49+00:00

I am trying to implement a generic (template) bidirectional linked list, similar to C#.NET

  • 0

I am trying to implement a generic (template) bidirectional linked list, similar to C#.NET implementation.

I wanted to build a “short cut” method to get at element with a certain index and decided to go with the subscript operator. I did just like in the instructions, and came up with something like this.

template <typename  T>
class List
{
public:
    T& operator[] (int index) 
    { 
        return iterator->GetCurrentValue(); //iterator is of type Iterator<T> and returns T&
    }
};

however when I get to use this in my code:

List<int>* myList = new List<int>();
...
int value=myList[i]; //i is int

I get a compiler error: main.cpp:18: error: cannot convert 'List<int>' to 'int' in initialization on the last line.

I tried it to return value, not reference, but still the same error.

Why is it interpreting int return value as List<int>?

I am using NetBeans with Cygwin gcc-c++.

  • 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-07T02:08:51+00:00Added an answer on June 7, 2026 at 2:08 am

    Why is it interpreting int return value as List<int>?

    It’s not. myList is a pointer to a List, it’s not a List itself. You’d need to use (*myList)[i].

    It’s quite unlikely that you really need dynamic allocation in this scenario, so my suggestion would be to not use a pointer, and to not use new.

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

Sidebar

Related Questions

I'm trying to implement a generic linked list. The struct for the node is
When using ASP.NET MVC plus Entity Framework, and trying to implement a generic repository
i am trying to implement a generic method which allows to output csv file
I am trying to implement a generic thread-safe Cache method, and I wonder how
I am trying to implement my own generic flatten for list objects which hold
I am trying to have a List of classes that implement a generic class
I'm trying to implement the generic method which is intended for converting objects of
I'm trying to implement generic method to put in a class a calculated value
I am trying to implement Koch's Snowflake. I have made a generic list, for
I'm trying to implement the first example http://www.dotnetperls.com/convert-list-string into my method but I'm having

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.