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

  • Home
  • SEARCH
  • 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 8907831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:01:06+00:00 2026-06-15T03:01:06+00:00

We have just been introduced to generics and templates in my comp sci class.

  • 0

We have just been introduced to generics and templates in my comp sci class.
I have been asked to create a generic container class that supports storage and retrieval of any data type.
I have all of my functions working okay, except when it comes to resize my array. I have the call for resize inside my insert function:

template< typename T >
void Container< T >::insert( T  magic)
{
    if (index == size)
    {
        resize();
    }
    containerPtr[index] = magic;
    index++;
}

The size variable is the size of the array and the index is the next insert location.

and here is my resize function:

template< typename T >
void Container< T >::resize()
{
    int doubSize = size * 2;
    Container< T > temp(doubSize);
    for (int i = 0; i < size; i++)
    {
        temp[i] = containerPtr[i];      // error 1 here
    }
    *containerPtr = temp;               // error 2 here
    size = doubSize;
}

My overloaded =

template< typename T >
const T Container< T >::operator=(const T& rhs)
{
    if(this == &rhs)
    {
        return *this;
    }
    return *rhs;
}

I receive the following errors when I try to compile:

1: error C2676: binary '[': 'Container<T>' does not define this operator or a conversion to a type acceptable to the predefined operator
2: error C2679: binary '=': no operator found which takes a right-hand operand of type 'Container<T>' (or there is no acceptable conversion)

I am not sure where I am going wrong here…

  • 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-15T03:01:07+00:00Added an answer on June 15, 2026 at 3:01 am

    2: error C2679: binary ‘=’: no operator found which takes a right-hand operand of type ‘Container’ (or there is no acceptable conversion)

    Is the more important error, it states that what ever you believe the types to be on

    *containerPtr = temp;

    this line of code is incorrect. It is impossible to assign a container<T> to a T value which is what you are trying to do. After you change temp to a pointer to a dynamically allocated array of T that is of the correct size(and remove the pointer deref on the assignment) the other error will go away on its own. Note you will also want to fix the memory leak where you forget to delete the previous array.

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

Sidebar

Related Questions

I have just been involved in writing an application that does not use Doctype's
I have just been introduced to the semantic web and it's family of functions
I have recently been introduced to EasyMock and have been asked to develop some
I have just been introduced to the Django framework and I would like to
i have just been introduced to simulated annealing and would like to understand it
I have just been helped on a problem I have here . var win
I have just been looking into Linq with ASP.Net. It is very neat indeed.
I recently have just been able to populate my core data DB. I have
This is probably more a design or style question: I have just been considering
I am fairly new to Flotr2 and I have just been building some simple

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.