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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:47:34+00:00 2026-06-16T11:47:34+00:00

I have class A and B. Class A has some fields. Class B is

  • 0

I have class A and B.

Class A has some fields.
Class B is like:

class B {
public:
    A* operator[]( int id ) {
        return m_field.at( id );
    }
    /* also tried this one, but there are the same errors
    A*& operator[]( int id ) {
        return m_field.at( id );
    }
    */
private:
    vector<A*> m_field;
};

why am I getting errors while executing:

B* B_instance = new B();
B_instance[some_int]->some_field_from_A;

the errors are:

error C2819: type ‘B’ does not have an overloaded member ‘operator ->’

error C2039: ‘some_field_from_A’ : is not a member of ‘B’

an why do I need to have -> operator overloading and how it should looks like? It doesn’t make sense to me.

I am using Visual Studio 2012.

  • 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-16T11:47:35+00:00Added an answer on June 16, 2026 at 11:47 am

    The indexing operator applies to something of type B, not of type B *. Therefore, to use the indexing operator, you need to first dereference your pointer (or not use one at all):

    (*B_instance)[some_int]...
    

    The reason for the error is because pointers can be indexed, as they are capable of representing an array, as in the example below:

    int arr[2] = {0, 1};
    int *p = arr; //array to pointer conversion
    p[1] = 2; // now arr is {0, 2}
    

    So when you index a B *, it gives you back a B that’s most likely out of bounds of your imaginary array. Then, you use the arrow operator on that B object when it expects a dot operator instead. Either way if you use pointers, dereference it, then index it, then use the arrow.

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

Sidebar

Related Questions

I have a C# class that has some functionality that I'd like to allow
I have a class Book which has some annotations like @Override , @Before ,
I have a simple Java class that has some methods: public class Utils {
I have a class that contains data from some model. This class has metadata
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
Writing an asp.net mvc app and i have something like this... Public Class AA
I have found some similar questions like this one, however there are so many
I have next tables Order , Transaction , Payment . Class Order has some
Suppose I have some class which has a property actor_ of type Actor .
I have a C++ class implementation file which has some constants. The constants appear

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.