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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:34:11+00:00 2026-05-25T22:34:11+00:00

I want to represent my object like an array. I mean that the programmer

  • 0

I want to represent my object like an array. I mean that the programmer can write in his code

myobject[3]=2

In the back (in myobject code) there isn’t an array at all, it’s only representation.

So I need to overload [] and = simultaneously.
How can this be done?

thank you,
and sorry about my poor English.

  • 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-05-25T22:34:12+00:00Added an answer on May 25, 2026 at 10:34 pm

    operator[] should return a reference to object you are trying to modify. It may be some kind of metaobject, that overloads operator= to do whatever you wish with your main object.

    Edit: As the OP clarified the problem, there is a way to do this. Look here:

    #include <vector>
    #include <iostream>
    
    int & func(std::vector<int> & a)
    {
        return a[3];
    }
    
    int main()
    {
        std::vector<int> a;
        a.push_back(1);
        a.push_back(2);
        a.push_back(3);
        a.push_back(4);
        func(a) = 111;
        std::cout << a[3] << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to represent a 2D shape in such a way that it can
I have a system that requires a unique 6-digit code to represent an object,
I have a complex JSON object that I want represent as C# class. I
We have objects that we want to represent in stacks (think of stacking items
I have a map that represents a DB object. I want to get 'well
Let's say I want to represent \q (or any other particular backslash-escaped character). That
I want a single number that represents the current date and time, like a
I want to create a component which can be used like: <mc:chart data=#{bean.data} width=200
I want to accept a string array of where conditions from the client like
In ActionScript 3, there are some classes that will represent a value rather than

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.