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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:16:19+00:00 2026-05-27T10:16:19+00:00

I have a template for a 3D array however I’m having problems compiling when

  • 0

I have a template for a 3D array however I’m having problems compiling when a variable of type Chunk (see typedef below) tries to do an index access.

template <typename T, int xMax, int yMax, int zMax>
class Volume {
public:
    class HelperIndex3 {
    public:
        HelperIndex3(Volume& p, int xx, int yy) : parent(p), x(xx), y(yy) {}
        T operator[] (int z) const {return parent.data[x][y][z];}
        T& operator[] (int z) {return parent.data[x][y][z];}
    private:
        Volume& parent;
        int x;
        int y;
    };
    class HelperIndex2 {
    public:
        HelperIndex2(Volume& p, int xx) : parent(p), x(xx) {}
        HelperIndex3 operator[] (int y) const {return HelperIndex3(parent, x, y);}
        HelperIndex3 operator[] (int y) {return HelperIndex3(parent, x, y);}
    private:
        Volume& parent;
        int x;
    };
    HelperIndex2 operator[] (int x) const {return HelperIndex2(*this, x);} //problem at this line
    HelperIndex2 operator[] (int x) {return HelperIndex2(*this, x);}

private:
    T data[xMax][yMax][zMax];
};

typedef Volume<unsigned char, 64, 64, 64> Chunk;

The problem line appears to want a const Volume& p in the HelperIndex2 constructor which I guess makes sense since I’m trying to use a const Chunk elsewhere – but I don’t know how to fix this. If I add a second constructor am I supposed to maintain two parent references one that is constant and another that is not? I fear this is going to balloon into a mess. If someone could explain the right way of handling this situation I would greatly appreciate it.

  • 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-27T10:16:19+00:00Added an answer on May 27, 2026 at 10:16 am

    You won’t get around maintaining two sets of proxy classes. This is completely analogous to the iterator and const_iterator nested classes of standard library containers.

    Since you are returning a copy of the proxy class, the proxy class that contains a mutable reference to the original object cannot possibly also be used for constant-only access to the original object, so you cannot get around some sort of two-fold approach. The semantics of the two are different: If all you have is an instance of the proxy class, you have to be able to know whether it allows mutating or only read-only access.

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

Sidebar

Related Questions

I have an array set inside a velocity template that contains some paths. The
I have an array of Paths which i want to read out with Template
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have 2 arrays that I would like to render in a template, one
i have template base.html and some children templates. I don't know how to set
I have template that looks like this: 100 template<size_t A0, size_t A1, size_t A2,
I am running Django trunk and have template Autoescaping on (default). Do I need
I am hosting SpiderMonkey in a current project and would like to have template
I have a template class that I serialize (call it C), for which I
I have some template code that I would prefer to have stored in a

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.