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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:17:23+00:00 2026-06-13T19:17:23+00:00

I’m working on a generic circular buffer but have hit a stumbling block when

  • 0

I’m working on a generic circular buffer but have hit a stumbling block when it comes to the copy constructor (see the code example below).

using namespace System;

/// A generic circular buffer with a fixed-size internal buffer which allows the caller to push data onto the buffer, pop data back off again and provides direct indexed access to any element.
generic<typename T>
public ref class CircularBuffer
{
protected:
    array<T, 1>^ m_buffer; /// The internal buffer used to store the data.
    unsigned int m_resultsInBuffer; /// A counter which records the number of results currently held in the buffer
    T m_nullValue; /// The value used to represent a null value within the buffer

public:
    CircularBuffer(unsigned int size, T nullValue):
      m_buffer(gcnew array<T, 1>(size)),
      m_nullValue(nullValue),
      m_resultsInBuffer(0)
    {

    }

    /// <summary>
    /// Copy constructor
    /// </summary>
    CircularBuffer(const CircularBuffer^& rhs)
    {
        CopyObject(rhs);
    }

    /// <summary>
    /// Assignment operator.
    /// </summary>
    /// <param name="objectToCopy"> The Zph2CsvConverter object to assign from. </param>
    /// <returns> This Zph2CsvConverter object following the assignment. </returns>
    CircularBuffer% operator=(const CircularBuffer^& objectToCopy)
    {
        CopyObject(objectToCopy);
        return *this;
    }

protected:
    /// <summary>
    /// Copies the member variables from a Zph2CsvConverter object to this object.
    /// </summary>
    /// <param name="objectToBeCopied"> The Zph2CsvConverter to be copied. </param>
    void CopyObject(const CircularBuffer^& objectToBeCopied)
    {
        m_buffer = safe_cast<array<T, 1>^>(objectToBeCopied->m_buffer->Clone());
        m_nullValue = objectToBeCopied->m_nullValue; // <-- "error C2440: '=' : cannot convert from 'const T' to 'T'"
        m_resultsInBuffer = objectToBeCopied->m_resultsInBuffer;
    }
};

Compiling this gives me error C2440: '=' : cannot convert from 'const T' to 'T'

Typically I’d be using this with my own ref classes which include pointers to managed and unmanaged memory so the contents of the buffer would need to be deep copied if the entire buffer is duplicated.

What am I missing here? Why can’t I copy from something of type const T to something of type T?

  • 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-13T19:17:25+00:00Added an answer on June 13, 2026 at 7:17 pm

    Another entry in the continuing saga of “C++/CLI doesn’t really support const”.

    The copy constructor in C++/CLI is T(T%). The assignment operator is T% operator=(T%). No const and no ref.

    A good place to see them used is vc/include/cliext, home of the STL/CLR implementation classes. Don’t use them.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't

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.